[Python-Dev] PEP 302 support for traceback, inspect, site, warnings, doctest, and linecache (original) (raw)
Phillip J. Eby pje at telecommunity.com
Mon Apr 10 19:03:02 CEST 2006
- Previous message: [Python-Dev] PSF Contributor Agreement for pysqlite
- Next message: [Python-Dev] DRAFT: python-dev summary for 2006-02-01 to 2006-02-15
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Here's my plan for implementing PEP 302 support (__loader__
sensitivity) for the above modules:
Change all of the
linecache
API functions (exceptclearcache()
) to add an optionalmodule_globals
argument, which they will use to obtain the__name__
and__loader__
in the event that the given filename doesn't exist, but appears to be the source file for the given module. (That is, if the basename of the filename is consistent with the last part of the__name__
in the module_globals, ifsys.modules[__name__].__dict__ is module_globals
, and the__loader__
(if any) in module_globals has aget_source()
method.)Change
inspect.getsourcefile()
to return the source path as long as the object's module has a__loader__
with aget_source()
method. This will ensure that otherinspect
functions will still try to load the source code for the object in question, even if it's in a zipfile or loaded by some other import mechanism.Change
inspect.findsource()
to pass the target object's module globals as an extra argument tolinecache.getlines()
Change the
traceback
module to supply frame globals to thelinecache
APIs it uses.Change the
site
module to not "absolutize"__file__
attributes of modules with__loader__
attributes;__loader__
objects are responsible for their own__file__
values. (Actually, if this is desirable behavior, the builtin import machinery should be doing it, not site.py!)Add an optional
module_globals
argument towarnings.warn_explicit()
, which will be passed through tolinecache.getlines()
if the warning is not ignored. (This will prime the line cache in case the warning is to be output.)Change
warnings.warn()
to pass the appropriate globals towarn_explicit()
.Change
doctest.testfile()
andDocTestSuite
to use the target module's__loader__.get_data()
method (if available) to load the given doctest file.Change
__patched_linecache_getlines()
indoctest
to accept an optionalmodule_globals
argument, to be passed through to the originalgetlines()
function.
I'm starting work on the above now. If I finish early enough today, I'll
follow up with plans for fixing pydoc
, which requires slightly more
extensive surgery, since it doesn't even support packages with multiple
__path__
entries yet, let alone PEP 302.
Please let me know if you have any questions or concerns.
- Previous message: [Python-Dev] PSF Contributor Agreement for pysqlite
- Next message: [Python-Dev] DRAFT: python-dev summary for 2006-02-01 to 2006-02-15
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]