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.
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index bd62c36..466b287 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -879,7 +879,11 @@
_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)