mirror of
https://github.com/python/cpython.git
synced 2025-09-07 01:11:26 +00:00
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:
parent
82a23fe392
commit
1c1dcbfd5d
4 changed files with 14 additions and 4 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue