From 8e4554027b8ba1e6fc3b9e1a67d3333a3399a6d6 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Wed, 14 Aug 2013 18:11:09 -0600 Subject: Closes issue #18698: ensure importlib.reload() returns the module out of sys.modules. --- Lib/importlib/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Lib/importlib/__init__.py') diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py index 6732977a2b..69ca9ce528 100644 --- a/Lib/importlib/__init__.py +++ b/Lib/importlib/__init__.py @@ -118,7 +118,9 @@ 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) - return module.__loader__.load_module(name) + module.__loader__.load_module(name) + # The module may have replaced itself in sys.modules! + return sys.modules[module.__name__] finally: try: del _RELOADING[name] -- cgit v1.2.1