diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py --- a/Lib/importlib/__init__.py +++ b/Lib/importlib/__init__.py @@ -10,6 +10,7 @@ # of a fully initialised version (either the frozen one or the one # initialised below if the frozen one is not available). import _imp # Just the builtin component, NOT the full Python module +import builtins import sys import types @@ -46,7 +47,7 @@ finder.invalidate_caches() -def find_spec(name, path=None): +def find_spec(name, package=None): """Return the spec for the specified module. First, sys.modules is checked to see if the module was already imported. If @@ -61,10 +62,17 @@ order for a submodule to get the correct spec. """ - if name not in sys.modules: - return _bootstrap._find_spec(name, path) + from .util import resolve_name + fullname = resolve_name(name, package) if name.startswith('.') else name + if fullname not in sys.modules: + parent_name = fullname.rpartition('.')[0] + if parent_name: + parent = builtins.__import__(parent_name, fromlist=['__path__']) + return _bootstrap._find_spec(fullname, parent.__path__) + else: + return _bootstrap._find_spec(fullname, None) else: - module = sys.modules[name] + module = sys.modules[fullname] if module is None: return None try: