Commit da9cf0ee authored by Brett Cannon's avatar Brett Cannon

Issue #17098: Be more stringent of setting __loader__ on early imported

modules. Also made test more rigorous.
parent e7387b47
......@@ -1704,10 +1704,13 @@ def _setup(sys_module, _imp_module):
BYTECODE_SUFFIXES = DEBUG_BYTECODE_SUFFIXES
module_type = type(sys)
for module in sys.modules.values():
for name, module in sys.modules.items():
if isinstance(module, module_type):
if not hasattr(module, '__loader__'):
module.__loader__ = BuiltinImporter
if name in sys.builtin_module_names:
module.__loader__ = BuiltinImporter
elif _imp.is_frozen(name):
module.__loader__ = FrozenImporter
self_module = sys.modules[__name__]
for builtin_name in ('_io', '_warnings', 'builtins', 'marshal'):
......
......@@ -184,6 +184,12 @@ class StartupTests(unittest.TestCase):
if isinstance(module, types.ModuleType):
self.assertTrue(hasattr(module, '__loader__'),
'{!r} lacks a __loader__ attribute'.format(name))
if name in sys.builtin_module_names:
self.assertEqual(importlib.machinery.BuiltinImporter,
module.__loader__)
elif imp.is_frozen(name):
self.assertEqual(importlib.machinery.FrozenImporter,
module.__loader__)
def test_main():
from test.support import run_unittest
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment