summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/__init__.py
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2013-11-01 04:22:15 (GMT)
committerEric Snow <ericsnowcurrently@gmail.com>2013-11-01 04:22:15 (GMT)
commitcdf601281f5909b4b7c6e1f10f3a80d3c216cdc3 (patch)
tree2bea84bd69350b853084377ab70bd17254bd4010 /Lib/importlib/__init__.py
parentdcdd05b0b4c23da0eb39d3b29d40f8865b6b73ee (diff)
downloadcpython-cdf601281f5909b4b7c6e1f10f3a80d3c216cdc3.zip
cpython-cdf601281f5909b4b7c6e1f10f3a80d3c216cdc3.tar.gz
cpython-cdf601281f5909b4b7c6e1f10f3a80d3c216cdc3.tar.bz2
Issue #19413: Restore pre-3.3 reload() semantics of re-finding modules.
Diffstat (limited to 'Lib/importlib/__init__.py')
-rw-r--r--Lib/importlib/__init__.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py
index 69ca9ce..e56e9c3 100644
--- a/Lib/importlib/__init__.py
+++ b/Lib/importlib/__init__.py
@@ -107,7 +107,7 @@ def reload(module):
if not module or not isinstance(module, types.ModuleType):
raise TypeError("reload() argument must be module")
name = module.__name__
- if name not in sys.modules:
+ if sys.modules.get(name) is not module:
msg = "module {} not in sys.modules"
raise ImportError(msg.format(name), name=name)
if name in _RELOADING:
@@ -118,7 +118,11 @@ def reload(module):
if parent_name and parent_name not in sys.modules:
msg = "parent {!r} not in sys.modules"
raise ImportError(msg.format(parent_name), name=parent_name)
- module.__loader__.load_module(name)
+ loader = _bootstrap._find_module(name, None)
+ if loader is None:
+ raise ImportError(_bootstrap._ERR_MSG.format(name), name=name)
+ module.__loader__ = loader
+ loader.load_module(name)
# The module may have replaced itself in sys.modules!
return sys.modules[module.__name__]
finally: