Issue #17098: Make sure every module has __loader__ defined.

Thanks to Thomas Heller for the bug report.
This commit is contained in:
Brett Cannon 2013-02-01 14:04:12 -05:00
parent 89fa86b035
commit 0ecd30b4af
4 changed files with 299 additions and 289 deletions

View file

@ -1703,9 +1703,11 @@ def _setup(sys_module, _imp_module):
else:
BYTECODE_SUFFIXES = DEBUG_BYTECODE_SUFFIXES
for module in (_imp, sys):
if not hasattr(module, '__loader__'):
module.__loader__ = BuiltinImporter
module_type = type(sys)
for module in sys.modules.values():
if isinstance(module, module_type):
if not hasattr(module, '__loader__'):
module.__loader__ = BuiltinImporter
self_module = sys.modules[__name__]
for builtin_name in ('_io', '_warnings', 'builtins', 'marshal'):