Issue #21226: Set all attrs in PyImport_ExecCodeModuleObject.

This commit is contained in:
Eric Snow 2014-05-12 17:54:55 -06:00
parent 0cc45baa3d
commit 08197a4616
5 changed files with 4331 additions and 4281 deletions

View file

@ -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: