If the stub module is not a package but the actual module is, it should not fail the import

This commit is contained in:
Dave Halter
2018-12-09 13:39:40 +01:00
parent 3ec194093d
commit aa4846bff6
2 changed files with 6 additions and 2 deletions

View File

@@ -172,7 +172,7 @@ class ModuleContext(ModuleMixin, TreeContext):
return os.path.abspath(self._path)
def _is_package(self):
def is_package(self):
return self._get_init_directory() is not None
def py__package__(self):
@@ -218,7 +218,7 @@ class ModuleContext(ModuleMixin, TreeContext):
is a list of paths (strings).
Raises an AttributeError if the module is not a package.
"""
if self._is_package():
if self.is_package():
return self._py__path__
else:
raise AttributeError('Only packages have __path__ attributes.')

View File

@@ -142,6 +142,10 @@ class TypeshedPlugin(BasePlugin):
if len(import_names) == 1:
map_ = self._cache_stub_file_map(evaluator.grammar.version_info)
elif isinstance(parent_module_context, StubModuleContext):
if not parent_module_context.stub_context.is_package():
# Only if it's a package (= a folder) something can be
# imported.
return context_set
path = parent_module_context.stub_context.py__path__()
map_ = _merge_create_stub_map(path)