1
0
forked from VimPlug/jedi

static analysis: Import tests working again.

This commit is contained in:
Dave Halter
2014-12-11 16:25:18 +01:00
parent 6818d3affa
commit 77fdbac234
3 changed files with 13 additions and 6 deletions

View File

@@ -216,6 +216,8 @@ def get_module_statements(module):
for scope in module.walk(): for scope in module.walk():
for imp in set(scope.imports): for imp in set(scope.imports):
import_names |= set(imp.get_defined_names()) import_names |= set(imp.get_defined_names())
if imp.is_nested():
import_names |= set(path[-1] for path in imp.paths())
stmts |= add_stmts(scope.statements) stmts |= add_stmts(scope.statements)
stmts |= add_stmts(r for r in scope.returns if r is not None) stmts |= add_stmts(r for r in scope.returns if r is not None)

View File

@@ -128,7 +128,8 @@ class ImportWrapper(pr.Base):
for s in scopes)) for s in scopes))
else: else:
print(self._import, scopes, rest) print(self._import, scopes, rest)
if self._import.type == 'import_from': if self._import.type == 'import_from' \
or importer.str_import_path == ('os', 'path'):
scopes = importer.follow_rest(scopes[0], rest) scopes = importer.follow_rest(scopes[0], rest)
else: else:
scopes = [] scopes = []

View File

@@ -717,7 +717,7 @@ class SubModule(Scope, Module):
# the future print statement). # the future print statement).
for imp in self.imports: for imp in self.imports:
if isinstance(imp, ImportFrom) and imp.level == 0: if isinstance(imp, ImportFrom) and imp.level == 0:
for path in imp._paths(): for path in imp.paths():
if [str(name) for name in path] == ['__future__', 'absolute_import']: if [str(name) for name in path] == ['__future__', 'absolute_import']:
return True return True
return False return False
@@ -986,7 +986,7 @@ class Import(Simple):
except KeyError: except KeyError:
pass pass
for path in self._paths(): for path in self.paths():
if name in path: if name in path:
return path[:path.index(name) + 1] return path[:path.index(name) + 1]
raise ValueError('Name should be defined in the import itself') raise ValueError('Name should be defined in the import itself')
@@ -1040,9 +1040,13 @@ class ImportFrom(Import):
""" """
The last name defined in a star import. The last name defined in a star import.
""" """
return self._paths()[-1][-1] return self.paths()[-1][-1]
def _paths(self): def paths(self):
"""
The import paths defined in an import statement. Typically an array
like this: ``[<Name: datetime>, <Name: date>]``.
"""
for n in self.children[1:]: for n in self.children[1:]:
if n not in ('.', '...'): if n not in ('.', '...'):
break break
@@ -1070,7 +1074,7 @@ class ImportName(Import):
"""The level parameter of ``__import__``.""" """The level parameter of ``__import__``."""
return 0 # Obviously 0 for imports without from. return 0 # Obviously 0 for imports without from.
def _paths(self): def paths(self):
return [path for path, alias in self._dotted_as_names()] return [path for path, alias in self._dotted_as_names()]
def _dotted_as_names(self): def _dotted_as_names(self):