forked from VimPlug/jedi
ImportPath -> ImportWrapper
This commit is contained in:
@@ -218,7 +218,7 @@ class Script(object):
|
||||
if s.isinstance(er.Function):
|
||||
names = s.get_magic_function_names()
|
||||
else:
|
||||
if isinstance(s, imports.ImportPath):
|
||||
if isinstance(s, imports.ImportWrapper):
|
||||
under = like + self._user_context.get_path_after_cursor()
|
||||
if under == 'import':
|
||||
current_line = self._user_context.get_position_line()
|
||||
@@ -363,7 +363,7 @@ class Script(object):
|
||||
"""
|
||||
def resolve_import_paths(scopes):
|
||||
for s in scopes.copy():
|
||||
if isinstance(s, imports.ImportPath):
|
||||
if isinstance(s, imports.ImportWrapper):
|
||||
scopes.remove(s)
|
||||
scopes.update(resolve_import_paths(set(s.follow())))
|
||||
return scopes
|
||||
@@ -394,7 +394,7 @@ class Script(object):
|
||||
|
||||
definitions = resolve_import_paths(definitions)
|
||||
d = set([classes.Definition(self._evaluator, s) for s in definitions
|
||||
if s is not imports.ImportPath.GlobalNamespace])
|
||||
if s is not imports.ImportWrapper.GlobalNamespace])
|
||||
return helpers.sorted_definitions(d)
|
||||
|
||||
def goto_assignments(self):
|
||||
@@ -408,7 +408,7 @@ class Script(object):
|
||||
"""
|
||||
results, _ = self._goto()
|
||||
d = [classes.Definition(self._evaluator, d) for d in set(results)
|
||||
if d is not imports.ImportPath.GlobalNamespace]
|
||||
if d is not imports.ImportWrapper.GlobalNamespace]
|
||||
return helpers.sorted_definitions(d)
|
||||
|
||||
def _goto(self, add_import_name=False):
|
||||
@@ -426,7 +426,7 @@ class Script(object):
|
||||
for d in defs:
|
||||
if isinstance(d.parent, pr.Import) \
|
||||
and d.start_pos == (0, 0):
|
||||
i = imports.ImportPath(self._evaluator, d.parent).follow(is_goto=True)
|
||||
i = imports.ImportWrapper(self._evaluator, d.parent).follow(is_goto=True)
|
||||
definitions.remove(d)
|
||||
definitions |= follow_inexistent_imports(i)
|
||||
return definitions
|
||||
|
||||
@@ -468,7 +468,7 @@ class Completion(BaseDefinition):
|
||||
"""
|
||||
definition = self._definition
|
||||
if isinstance(self._definition, pr.Import):
|
||||
i = imports.ImportPath(self._evaluator, self._definition)
|
||||
i = imports.ImportWrapper(self._evaluator, self._definition)
|
||||
if len(i.import_path) > 1 or not fast:
|
||||
followed = self._follow_statements_imports()
|
||||
if followed:
|
||||
@@ -487,7 +487,7 @@ class Completion(BaseDefinition):
|
||||
description, look at :attr:`jedi.api.classes.BaseDefinition.type`.
|
||||
"""
|
||||
if isinstance(self._definition, pr.Import):
|
||||
i = imports.ImportPath(self._evaluator, self._definition)
|
||||
i = imports.ImportWrapper(self._evaluator, self._definition)
|
||||
if len(i.import_path) <= 1:
|
||||
return 'module'
|
||||
|
||||
@@ -504,7 +504,7 @@ class Completion(BaseDefinition):
|
||||
# imports completion is very complicated and needs to be treated
|
||||
# separately in Completion.
|
||||
if self._definition.isinstance(pr.Import) and self._definition.alias is None:
|
||||
i = imports.ImportPath(self._evaluator, self._definition, True)
|
||||
i = imports.ImportWrapper(self._evaluator, self._definition, True)
|
||||
import_path = i.import_path + (unicode(self._name),)
|
||||
try:
|
||||
return imports.get_importer(self._evaluator, import_path,
|
||||
|
||||
@@ -40,7 +40,7 @@ def get_on_import_stmt(evaluator, user_context, user_stmt, is_like_search=False)
|
||||
context = user_context.get_context()
|
||||
just_from = next(context) == 'from'
|
||||
|
||||
i = imports.ImportPath(evaluator, user_stmt, is_like_search,
|
||||
i = imports.ImportWrapper(evaluator, user_stmt, is_like_search,
|
||||
kill_count=kill_count, direct_resolve=True,
|
||||
is_just_from=just_from)
|
||||
return i, cur_name_part
|
||||
|
||||
@@ -75,7 +75,7 @@ def usages(evaluator, definitions, search_name, mods):
|
||||
imps.append((count, name_part))
|
||||
|
||||
for used_count, name_part in imps:
|
||||
i = imports.ImportPath(evaluator, stmt, kill_count=count - used_count,
|
||||
i = imports.ImportWrapper(evaluator, stmt, kill_count=count - used_count,
|
||||
direct_resolve=True)
|
||||
f = i.follow(is_goto=True)
|
||||
if set(f) & set(definitions):
|
||||
@@ -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.ImportPath(evaluator, d.parent, direct_resolve=True)
|
||||
s = imports.ImportWrapper(evaluator, d.parent, direct_resolve=True)
|
||||
with common.ignored(IndexError):
|
||||
new.add(s.follow(is_goto=True)[0])
|
||||
return set(definitions) | new
|
||||
|
||||
@@ -34,9 +34,9 @@ class ModuleNotFound(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class ImportPath(pr.Base):
|
||||
class ImportWrapper(pr.Base):
|
||||
"""
|
||||
An ImportPath is the path of a `pr.Import` object.
|
||||
An ImportWrapper is the path of a `pr.Import` object.
|
||||
"""
|
||||
class GlobalNamespace(object):
|
||||
def __init__(self):
|
||||
@@ -83,7 +83,7 @@ class ImportPath(pr.Base):
|
||||
def get_defined_names(self, on_import_stmt=False):
|
||||
names = []
|
||||
for scope in self.follow():
|
||||
if scope is ImportPath.GlobalNamespace:
|
||||
if scope is ImportWrapper.GlobalNamespace:
|
||||
if not self._is_relative_import():
|
||||
names += self._get_module_names()
|
||||
|
||||
@@ -216,7 +216,7 @@ class ImportPath(pr.Base):
|
||||
if self._is_nested_import():
|
||||
scopes.append(self._get_nested_import(scope))
|
||||
else:
|
||||
scopes = [ImportPath.GlobalNamespace]
|
||||
scopes = [ImportWrapper.GlobalNamespace]
|
||||
debug.dbg('after import: %s', scopes)
|
||||
self._evaluator.recursion_detector.pop_stmt()
|
||||
return scopes
|
||||
@@ -424,7 +424,7 @@ def strip_imports(evaluator, scopes):
|
||||
result = []
|
||||
for s in scopes:
|
||||
if isinstance(s, pr.Import):
|
||||
result += ImportPath(evaluator, s).follow()
|
||||
result += ImportWrapper(evaluator, s).follow()
|
||||
else:
|
||||
result.append(s)
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user