Close #24748: Restore imp.load_dynamic compatibility

To resolve a compatibility problem found with py2exe and
pywin32, imp.load_dynamic() once again ignores previously loaded modules
to support Python modules replacing themselves with extension modules.

Patch by Petr Viktorin.
This commit is contained in:
Nick Coghlan 2015-09-05 21:05:05 +10:00
parent 1b66910537
commit 9d3c61c86a
5 changed files with 49 additions and 1 deletions

View file

@ -334,6 +334,12 @@ if create_dynamic:
"""
import importlib.machinery
loader = importlib.machinery.ExtensionFileLoader(name, path)
return loader.load_module()
# Issue #24748: Skip the sys.modules check in _load_module_shim;
# always load new extension
spec = importlib.machinery.ModuleSpec(
name=name, loader=loader, origin=path)
return _load(spec)
else:
load_dynamic = None