forked from VimPlug/jedi
introduce a NestedImportModule class
This commit is contained in:
@@ -190,7 +190,11 @@ class ImportWrapper(pr.Base):
|
|||||||
debug.warning('Module not found: %s', self.import_stmt)
|
debug.warning('Module not found: %s', self.import_stmt)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
scopes = [scope]
|
if self._is_nested_import():
|
||||||
|
scopes = [NestedImportModule(scope, self._get_nested_import(scope))]
|
||||||
|
else:
|
||||||
|
scopes = [scope]
|
||||||
|
|
||||||
scopes += remove_star_imports(self._evaluator, scope)
|
scopes += remove_star_imports(self._evaluator, scope)
|
||||||
|
|
||||||
# follow the rest of the import (not FS -> classes, functions)
|
# follow the rest of the import (not FS -> classes, functions)
|
||||||
@@ -212,9 +216,6 @@ class ImportWrapper(pr.Base):
|
|||||||
scopes = list(chain.from_iterable(
|
scopes = list(chain.from_iterable(
|
||||||
self._evaluator.follow_path(iter(rest), [s], s)
|
self._evaluator.follow_path(iter(rest), [s], s)
|
||||||
for s in scopes))
|
for s in scopes))
|
||||||
|
|
||||||
if self._is_nested_import():
|
|
||||||
scopes.append(self._get_nested_import(scope))
|
|
||||||
else:
|
else:
|
||||||
scopes = [ImportWrapper.GlobalNamespace]
|
scopes = [ImportWrapper.GlobalNamespace]
|
||||||
debug.dbg('after import: %s', scopes)
|
debug.dbg('after import: %s', scopes)
|
||||||
@@ -222,6 +223,24 @@ class ImportWrapper(pr.Base):
|
|||||||
return scopes
|
return scopes
|
||||||
|
|
||||||
|
|
||||||
|
class NestedImportModule(pr.Module):
|
||||||
|
def __init__(self, module, nested_import):
|
||||||
|
self._module = module
|
||||||
|
self._nested_import = nested_import
|
||||||
|
|
||||||
|
def get_defined_names(self):
|
||||||
|
nested = self._nested_import.namespace
|
||||||
|
print(nested)
|
||||||
|
return self._module.get_defined_names() + [nested]
|
||||||
|
|
||||||
|
def __getattr__(self, name):
|
||||||
|
return getattr(self._module, name)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "<%s: %s>" % (self.__class__.__name__,
|
||||||
|
self._module)
|
||||||
|
|
||||||
|
|
||||||
def get_importer(evaluator, import_path, module, level=0):
|
def get_importer(evaluator, import_path, module, level=0):
|
||||||
"""
|
"""
|
||||||
Checks the evaluator caches first, which resembles the ``sys.modules``
|
Checks the evaluator caches first, which resembles the ``sys.modules``
|
||||||
|
|||||||
Reference in New Issue
Block a user