Commit 813f7ac7 authored by Brett Cannon's avatar Brett Cannon

merge

parents da53a249 bde06f7e
......@@ -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__'):
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'):
......
......@@ -4,6 +4,7 @@ import importlib
from importlib import machinery
import sys
from test import support
import types
import unittest
......@@ -175,12 +176,28 @@ class FrozenImportlibTests(unittest.TestCase):
machinery.FrozenImporter))
class StartupTests(unittest.TestCase):
def test_everyone_has___loader__(self):
# Issue #17098: all modules should have __loader__ defined.
for name, module in sys.modules.items():
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
run_unittest(ImportModuleTests,
FindLoaderTests,
InvalidateCacheTests,
FrozenImportlibTests)
FrozenImportlibTests,
StartupTests)
if __name__ == '__main__':
......
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