diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2013-12-10 02:59:10 (GMT) |
---|---|---|
committer | Eric Snow <ericsnowcurrently@gmail.com> | 2013-12-10 02:59:10 (GMT) |
commit | c1e7c747f92a27f1f2bb392dbbfbd2817591f44f (patch) | |
tree | 5b704ab3437269d9811aee36233d897500a24f76 /Lib/importlib | |
parent | fc25d629aba73a0da3fa0dd9de640a117fd76c29 (diff) | |
download | cpython-c1e7c747f92a27f1f2bb392dbbfbd2817591f44f.zip cpython-c1e7c747f92a27f1f2bb392dbbfbd2817591f44f.tar.gz cpython-c1e7c747f92a27f1f2bb392dbbfbd2817591f44f.tar.bz2 |
Issue 19851: Fix a regression in reloading submodules.
Diffstat (limited to 'Lib/importlib')
-rw-r--r-- | Lib/importlib/__init__.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py index 3e969bb..a4b1f55 100644 --- a/Lib/importlib/__init__.py +++ b/Lib/importlib/__init__.py @@ -153,10 +153,17 @@ def reload(module): _RELOADING[name] = module try: parent_name = name.rpartition('.')[0] - 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) - spec = module.__spec__ = _bootstrap._find_spec(name, None, module) + if parent_name: + try: + parent = sys.modules[parent_name] + except KeyError: + msg = "parent {!r} not in sys.modules" + raise ImportError(msg.format(parent_name), name=parent_name) + else: + pkgpath = parent.__path__ + else: + pkgpath = None + spec = module.__spec__ = _bootstrap._find_spec(name, pkgpath, module) methods = _bootstrap._SpecMethods(spec) methods.exec(module) # The module may have replaced itself in sys.modules! |