Trying to import a submodule from another module and not a package was raising

AttributeError in importlib when it should be an ImportError.

Found when running importlib against test_runpy.
This commit is contained in:
Brett Cannon 2009-08-30 20:22:21 +00:00
parent 82a23fe392
commit 1c1dcbfd5d
4 changed files with 14 additions and 4 deletions

View file

@ -879,7 +879,11 @@ def _gcd_import(name, package=None, level=0):
_gcd_import(parent)
# Backwards-compatibility; be nicer to skip the dict lookup.
parent_module = sys.modules[parent]
path = parent_module.__path__
try:
path = parent_module.__path__
except AttributeError:
raise ImportError("no module named {}; "
"{} is not a package".format(name, parent))
meta_path = sys.meta_path + _IMPLICIT_META_PATH
for finder in meta_path:
loader = finder.find_module(name, path)