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