Issue #15210: If _frozen_importlib is not found in sys.modules by
importlib.__init__, then catch the KeyError raised, not ImportError.
This commit is contained in:
parent
1e331560ee
commit
8e2f5564b3
|
@ -7,7 +7,7 @@ import sys
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_bootstrap = sys.modules['_frozen_importlib']
|
_bootstrap = sys.modules['_frozen_importlib']
|
||||||
except ImportError:
|
except KeyError:
|
||||||
from . import _bootstrap
|
from . import _bootstrap
|
||||||
_bootstrap._setup(sys, imp)
|
_bootstrap._setup(sys, imp)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -160,9 +160,30 @@ class InvalidateCacheTests(unittest.TestCase):
|
||||||
importlib.invalidate_caches() # Shouldn't trigger an exception.
|
importlib.invalidate_caches() # Shouldn't trigger an exception.
|
||||||
|
|
||||||
|
|
||||||
|
class FrozenImportlibTests(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_no_frozen_importlib(self):
|
||||||
|
# Should be able to import w/o _frozen_importlib being defined.
|
||||||
|
modules = {}
|
||||||
|
for name in ('importlib', 'importlib.__init__', 'importlib._bootstrap',
|
||||||
|
'_frozen_importlib'):
|
||||||
|
try:
|
||||||
|
modules[name] = sys.modules[name]
|
||||||
|
del sys.modules[name]
|
||||||
|
except KeyError:
|
||||||
|
continue
|
||||||
|
modules['_frozen_importlib'] = None
|
||||||
|
import importlib
|
||||||
|
for name, module in modules.items():
|
||||||
|
sys.modules[name] = module
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
from test.support import run_unittest
|
from test.support import run_unittest
|
||||||
run_unittest(ImportModuleTests, FindLoaderTests, InvalidateCacheTests)
|
run_unittest(ImportModuleTests,
|
||||||
|
FindLoaderTests,
|
||||||
|
InvalidateCacheTests,
|
||||||
|
FrozenImportlibTests)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -17,6 +17,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #15210: Catch KeyError when imprortlib.__init__ can't find
|
||||||
|
_frozen_importlib in sys.modules, not ImportError.
|
||||||
|
|
||||||
- Issue #15030: importlib.abc.PyPycLoader now supports the new source size
|
- Issue #15030: importlib.abc.PyPycLoader now supports the new source size
|
||||||
header field in .pyc files.
|
header field in .pyc files.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue