diff options
author | Brett Cannon <brett@python.org> | 2013-02-01 20:31:49 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2013-02-01 20:31:49 (GMT) |
commit | da9cf0eef8c9cb338ad71330345423c9de2e0a01 (patch) | |
tree | 6308525f9a2e565f482746c6b399e808773bef73 /Lib | |
parent | e7387b470876e6f3a2f4b45ed47a7a061c9fdc99 (diff) | |
download | cpython-da9cf0eef8c9cb338ad71330345423c9de2e0a01.zip cpython-da9cf0eef8c9cb338ad71330345423c9de2e0a01.tar.gz cpython-da9cf0eef8c9cb338ad71330345423c9de2e0a01.tar.bz2 |
Issue #17098: Be more stringent of setting __loader__ on early imported
modules. Also made test more rigorous.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/importlib/_bootstrap.py | 7 | ||||
-rw-r--r-- | Lib/test/test_importlib/test_api.py | 6 |
2 files changed, 11 insertions, 2 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py index 320ec64..15fe156 100644 --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -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'): diff --git a/Lib/test/test_importlib/test_api.py b/Lib/test/test_importlib/test_api.py index 3c3ba89..5d63d85 100644 --- a/Lib/test/test_importlib/test_api.py +++ b/Lib/test/test_importlib/test_api.py @@ -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 |