summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/_bootstrap.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/importlib/_bootstrap.py')
-rw-r--r--Lib/importlib/_bootstrap.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index ec10532..a06a02f 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -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