summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2014-05-12 23:54:55 (GMT)
committerEric Snow <ericsnowcurrently@gmail.com>2014-05-12 23:54:55 (GMT)
commit08197a4616f6294e21672fd8ebb5da7ce956c8e5 (patch)
treef288f00937c5fbb449f7edfb782654aee38dea64 /Lib/importlib
parent0cc45baa3d160810f371ef7b69f4b56437bde790 (diff)
downloadcpython-08197a4616f6294e21672fd8ebb5da7ce956c8e5.zip
cpython-08197a4616f6294e21672fd8ebb5da7ce956c8e5.tar.gz
cpython-08197a4616f6294e21672fd8ebb5da7ce956c8e5.tar.bz2
Issue #21226: Set all attrs in PyImport_ExecCodeModuleObject.
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/_bootstrap.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index beaa9b3..b8836c1 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -1220,6 +1220,29 @@ class _SpecMethods:
return self._load_unlocked()
+def _fix_up_module(ns, name, pathname, cpathname=None):
+ # This function is used by PyImport_ExecCodeModuleObject().
+ loader = ns.get('__loader__')
+ spec = ns.get('__spec__')
+ if not loader:
+ if spec:
+ loader = spec.loader
+ elif pathname == cpathname:
+ loader = SourcelessFileLoader(name, pathname)
+ else:
+ loader = SourceFileLoader(name, pathname)
+ if not spec:
+ spec = spec_from_file_location(name, pathname, loader=loader)
+ try:
+ ns['__spec__'] = spec
+ ns['__loader__'] = loader
+ ns['__file__'] = pathname
+ ns['__cached__'] = cpathname
+ except Exception:
+ # Not important enough to report.
+ pass
+
+
# Loaders #####################################################################
class BuiltinImporter: