forked from VimPlug/jedi
fixed NestedImportModule
This commit is contained in:
@@ -184,6 +184,10 @@ class FakeStatement(pr.Statement):
|
|||||||
|
|
||||||
|
|
||||||
class FakeName(pr.Name):
|
class FakeName(pr.Name):
|
||||||
def __init__(self, name, parent=None):
|
def __init__(self, name_or_names, parent=None):
|
||||||
p = 0, 0
|
p = 0, 0
|
||||||
super(FakeName, self).__init__(FakeSubModule, [(name, p)], p, p, parent)
|
if isinstance(name_or_names, list):
|
||||||
|
names = [(n, p) for n in name_or_names]
|
||||||
|
else:
|
||||||
|
names = [(name_or_names, p)]
|
||||||
|
super(FakeName, self).__init__(FakeSubModule, names, p, p, parent)
|
||||||
|
|||||||
@@ -158,23 +158,6 @@ class ImportWrapper(pr.Base):
|
|||||||
and len(self.import_stmt.namespace.names) > 1 \
|
and len(self.import_stmt.namespace.names) > 1 \
|
||||||
and not self.direct_resolve
|
and not self.direct_resolve
|
||||||
|
|
||||||
def _get_nested_import(self, parent):
|
|
||||||
"""
|
|
||||||
See documentation of `self._is_nested_import`.
|
|
||||||
Generates an Import statement, that can be used to fake nested imports.
|
|
||||||
"""
|
|
||||||
i = self.import_stmt
|
|
||||||
# This is not an existing Import statement. Therefore, set position to
|
|
||||||
# 0 (0 is not a valid line number).
|
|
||||||
zero = (0, 0)
|
|
||||||
names = [(unicode(name_part), name_part.start_pos)
|
|
||||||
for name_part in i.namespace.names[1:]]
|
|
||||||
n = pr.Name(i._sub_module, names, zero, zero, self.import_stmt)
|
|
||||||
new = pr.Import(i._sub_module, zero, zero, n)
|
|
||||||
new.parent = parent
|
|
||||||
debug.dbg('Generated a nested import: %s', new)
|
|
||||||
return new
|
|
||||||
|
|
||||||
def _is_relative_import(self):
|
def _is_relative_import(self):
|
||||||
return bool(self.import_stmt.relative_count)
|
return bool(self.import_stmt.relative_count)
|
||||||
|
|
||||||
@@ -191,7 +174,7 @@ class ImportWrapper(pr.Base):
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
if self._is_nested_import():
|
if self._is_nested_import():
|
||||||
scopes = [NestedImportModule(scope, self._get_nested_import(scope))]
|
scopes = [NestedImportModule(scope, self.import_stmt)]
|
||||||
else:
|
else:
|
||||||
scopes = [scope]
|
scopes = [scope]
|
||||||
|
|
||||||
@@ -228,9 +211,24 @@ class NestedImportModule(pr.Module):
|
|||||||
self._module = module
|
self._module = module
|
||||||
self._nested_import = nested_import
|
self._nested_import = nested_import
|
||||||
|
|
||||||
|
def _get_nested_import_name(self):
|
||||||
|
"""
|
||||||
|
See documentation of `self._is_nested_import`.
|
||||||
|
Generates an Import statement, that can be used to fake nested imports.
|
||||||
|
"""
|
||||||
|
i = self._nested_import
|
||||||
|
# This is not an existing Import statement. Therefore, set position to
|
||||||
|
# 0 (0 is not a valid line number).
|
||||||
|
zero = (0, 0)
|
||||||
|
names = [unicode(name_part) for name_part in i.namespace.names[1:]]
|
||||||
|
name = helpers.FakeName(names, self._nested_import)
|
||||||
|
new = pr.Import(i._sub_module, zero, zero, name)
|
||||||
|
new.parent = self._module
|
||||||
|
debug.dbg('Generated a nested import: %s', new)
|
||||||
|
return helpers.FakeName(str(i.namespace.names[1]), new)
|
||||||
|
|
||||||
def get_defined_names(self):
|
def get_defined_names(self):
|
||||||
nested = self._nested_import.namespace
|
nested = self._get_nested_import_name()
|
||||||
print(nested)
|
|
||||||
return self._module.get_defined_names() + [nested]
|
return self._module.get_defined_names() + [nested]
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
|
|||||||
Reference in New Issue
Block a user