diff options
author | Brett Cannon <brett@python.org> | 2011-03-23 23:14:42 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2011-03-23 23:14:42 (GMT) |
commit | 442c9b92d8f34853d1151abf69f07ff8147fc417 (patch) | |
tree | 15d438c0c84683dc27081628d5df763aebfc7ef0 /Lib/importlib | |
parent | a7468bc5c6153784fb9ab35baf030162208d852d (diff) | |
download | cpython-442c9b92d8f34853d1151abf69f07ff8147fc417.zip cpython-442c9b92d8f34853d1151abf69f07ff8147fc417.tar.gz cpython-442c9b92d8f34853d1151abf69f07ff8147fc417.tar.bz2 |
Make importlib compatible with __import__ by "fixing" code.co_filename
paths.
__import__ does a little trick when importing from bytecode by
back-patching the co_filename paths to point to the file location
where the code object was loaded from, *not* where the code object was
originally created. This allows co_filename to point to a valid path.
Problem is that co_filename is immutable from Python, so a private
function -- imp._fix_co_filename() -- had to be introduced in order to
get things working properly. Originally the plan was to add a file
argument to marshal.loads(), but that failed as the algorithm used by
__import__ is not fully recursive as one might expect, so to be fully
backwards-compatible the code used by __import__ needed to be exposed.
This closes issue #6811 by taking a different approach than outlined
in the issue.
Diffstat (limited to 'Lib/importlib')
-rw-r--r-- | Lib/importlib/_bootstrap.py | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py index f2ef1cf..18ea85c 100644 --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -404,6 +404,7 @@ class SourceLoader(_LoaderBasics): else: found = marshal.loads(bytes_data) if isinstance(found, code_type): + imp._fix_co_filename(found, source_path) return found else: msg = "Non-code object in {}" |