forked from VimPlug/jedi
imports cleanup & documentation
This commit is contained in:
@@ -591,7 +591,7 @@ class Script(object):
|
||||
for stmt in statements:
|
||||
if isinstance(stmt, pr.Import):
|
||||
imps = imports.ImportWrapper(self._evaluator, stmt,
|
||||
direct_resolve=True).follow()
|
||||
nested_resolve=True).follow()
|
||||
if stmt.is_nested() and any(not isinstance(i, pr.Module) for i in imps):
|
||||
analysis.add(self._evaluator, 'import-error', stmt)
|
||||
else:
|
||||
|
||||
@@ -41,6 +41,6 @@ def get_on_import_stmt(evaluator, user_context, user_stmt, is_like_search=False)
|
||||
just_from = next(context) == 'from'
|
||||
|
||||
i = imports.ImportWrapper(evaluator, user_stmt, is_like_search,
|
||||
kill_count=kill_count, direct_resolve=True,
|
||||
kill_count=kill_count, nested_resolve=True,
|
||||
is_just_from=just_from)
|
||||
return i, cur_name_part
|
||||
|
||||
@@ -76,7 +76,7 @@ def usages(evaluator, definitions, search_name, mods):
|
||||
|
||||
for used_count, name_part in imps:
|
||||
i = imports.ImportWrapper(evaluator, stmt, kill_count=count - used_count,
|
||||
direct_resolve=True)
|
||||
nested_resolve=True)
|
||||
f = i.follow(is_goto=True)
|
||||
if set(f) & set(definitions):
|
||||
names.append(classes.Definition(evaluator, name_part))
|
||||
@@ -91,7 +91,7 @@ def usages_add_import_modules(evaluator, definitions, search_name):
|
||||
new = set()
|
||||
for d in definitions:
|
||||
if isinstance(d.parent, pr.Import):
|
||||
s = imports.ImportWrapper(evaluator, d.parent, direct_resolve=True)
|
||||
s = imports.ImportWrapper(evaluator, d.parent, nested_resolve=True)
|
||||
with common.ignored(IndexError):
|
||||
new.add(s.follow(is_goto=True)[0])
|
||||
return set(definitions) | new
|
||||
|
||||
@@ -46,11 +46,18 @@ class ImportWrapper(pr.Base):
|
||||
GlobalNamespace = GlobalNamespace()
|
||||
|
||||
def __init__(self, evaluator, import_stmt, is_like_search=False, kill_count=0,
|
||||
direct_resolve=False, is_just_from=False):
|
||||
nested_resolve=False, is_just_from=False):
|
||||
"""
|
||||
:param is_like_search: If the wrapper is used for autocompletion.
|
||||
:param kill_count: Placement of the import, sometimes we only want to
|
||||
resole a part of the import.
|
||||
:param nested_resolve: Resolves nested imports fully.
|
||||
:param is_just_from: Bool if the second part is missing.
|
||||
"""
|
||||
self._evaluator = evaluator
|
||||
self.import_stmt = import_stmt
|
||||
self.is_like_search = is_like_search
|
||||
self.direct_resolve = direct_resolve
|
||||
self.nested_resolve = nested_resolve
|
||||
self.is_just_from = is_just_from
|
||||
|
||||
self.is_partial_import = bool(max(0, kill_count))
|
||||
@@ -60,7 +67,7 @@ class ImportWrapper(pr.Base):
|
||||
if import_stmt.from_ns:
|
||||
import_path += import_stmt.from_ns.names
|
||||
if import_stmt.namespace:
|
||||
if self.import_stmt.is_nested() and not direct_resolve:
|
||||
if self.import_stmt.is_nested() and not nested_resolve:
|
||||
import_path.append(import_stmt.namespace.names[0])
|
||||
else:
|
||||
import_path += import_stmt.namespace.names
|
||||
@@ -163,7 +170,7 @@ class ImportWrapper(pr.Base):
|
||||
analysis.add(self._evaluator, 'import-error', self.import_stmt)
|
||||
return []
|
||||
|
||||
if self.import_stmt.is_nested() and not self.direct_resolve:
|
||||
if self.import_stmt.is_nested() and not self.nested_resolve:
|
||||
scopes = [NestedImportModule(scope, self.import_stmt)]
|
||||
else:
|
||||
scopes = [scope]
|
||||
|
||||
Reference in New Issue
Block a user