mirror of
https://github.com/python/cpython.git
synced 2025-10-07 07:31:46 +00:00
Issue #19413: Restore pre-3.3 reload() semantics of re-finding modules.
This commit is contained in:
parent
dcdd05b0b4
commit
cdf601281f
5 changed files with 642 additions and 507 deletions
|
@ -1510,15 +1510,19 @@ def _find_module(name, path):
|
|||
"""Find a module's loader."""
|
||||
if not sys.meta_path:
|
||||
_warnings.warn('sys.meta_path is empty', ImportWarning)
|
||||
is_reload = name in sys.modules
|
||||
for finder in sys.meta_path:
|
||||
with _ImportLockContext():
|
||||
loader = finder.find_module(name, path)
|
||||
if loader is not None:
|
||||
# The parent import may have already imported this module.
|
||||
if name not in sys.modules:
|
||||
if is_reload or name not in sys.modules:
|
||||
return loader
|
||||
else:
|
||||
return sys.modules[name].__loader__
|
||||
try:
|
||||
return sys.modules[name].__loader__
|
||||
except AttributeError:
|
||||
return loader
|
||||
else:
|
||||
return None
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue