1
0
forked from VimPlug/jedi

ImportPath -> ImportWrapper

This commit is contained in:
Dave Halter
2014-04-30 17:13:47 +02:00
parent 0322869202
commit e5326acf8f
5 changed files with 19 additions and 19 deletions

View File

@@ -218,7 +218,7 @@ class Script(object):
if s.isinstance(er.Function): if s.isinstance(er.Function):
names = s.get_magic_function_names() names = s.get_magic_function_names()
else: else:
if isinstance(s, imports.ImportPath): if isinstance(s, imports.ImportWrapper):
under = like + self._user_context.get_path_after_cursor() under = like + self._user_context.get_path_after_cursor()
if under == 'import': if under == 'import':
current_line = self._user_context.get_position_line() current_line = self._user_context.get_position_line()
@@ -363,7 +363,7 @@ class Script(object):
""" """
def resolve_import_paths(scopes): def resolve_import_paths(scopes):
for s in scopes.copy(): for s in scopes.copy():
if isinstance(s, imports.ImportPath): if isinstance(s, imports.ImportWrapper):
scopes.remove(s) scopes.remove(s)
scopes.update(resolve_import_paths(set(s.follow()))) scopes.update(resolve_import_paths(set(s.follow())))
return scopes return scopes
@@ -394,7 +394,7 @@ class Script(object):
definitions = resolve_import_paths(definitions) definitions = resolve_import_paths(definitions)
d = set([classes.Definition(self._evaluator, s) for s in 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) return helpers.sorted_definitions(d)
def goto_assignments(self): def goto_assignments(self):
@@ -408,7 +408,7 @@ class Script(object):
""" """
results, _ = self._goto() results, _ = self._goto()
d = [classes.Definition(self._evaluator, d) for d in set(results) 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) return helpers.sorted_definitions(d)
def _goto(self, add_import_name=False): def _goto(self, add_import_name=False):
@@ -426,7 +426,7 @@ class Script(object):
for d in defs: for d in defs:
if isinstance(d.parent, pr.Import) \ if isinstance(d.parent, pr.Import) \
and d.start_pos == (0, 0): 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.remove(d)
definitions |= follow_inexistent_imports(i) definitions |= follow_inexistent_imports(i)
return definitions return definitions

View File

@@ -468,7 +468,7 @@ class Completion(BaseDefinition):
""" """
definition = self._definition definition = self._definition
if isinstance(self._definition, pr.Import): 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: if len(i.import_path) > 1 or not fast:
followed = self._follow_statements_imports() followed = self._follow_statements_imports()
if followed: if followed:
@@ -487,7 +487,7 @@ class Completion(BaseDefinition):
description, look at :attr:`jedi.api.classes.BaseDefinition.type`. description, look at :attr:`jedi.api.classes.BaseDefinition.type`.
""" """
if isinstance(self._definition, pr.Import): 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: if len(i.import_path) <= 1:
return 'module' return 'module'
@@ -504,7 +504,7 @@ class Completion(BaseDefinition):
# imports completion is very complicated and needs to be treated # imports completion is very complicated and needs to be treated
# separately in Completion. # separately in Completion.
if self._definition.isinstance(pr.Import) and self._definition.alias is None: 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),) import_path = i.import_path + (unicode(self._name),)
try: try:
return imports.get_importer(self._evaluator, import_path, return imports.get_importer(self._evaluator, import_path,

View File

@@ -40,7 +40,7 @@ def get_on_import_stmt(evaluator, user_context, user_stmt, is_like_search=False)
context = user_context.get_context() context = user_context.get_context()
just_from = next(context) == 'from' 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, kill_count=kill_count, direct_resolve=True,
is_just_from=just_from) is_just_from=just_from)
return i, cur_name_part return i, cur_name_part

View File

@@ -75,7 +75,7 @@ def usages(evaluator, definitions, search_name, mods):
imps.append((count, name_part)) imps.append((count, name_part))
for used_count, name_part in imps: 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) direct_resolve=True)
f = i.follow(is_goto=True) f = i.follow(is_goto=True)
if set(f) & set(definitions): if set(f) & set(definitions):
@@ -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.ImportPath(evaluator, d.parent, direct_resolve=True) s = imports.ImportWrapper(evaluator, d.parent, direct_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

View File

@@ -34,9 +34,9 @@ class ModuleNotFound(Exception):
pass 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): class GlobalNamespace(object):
def __init__(self): def __init__(self):
@@ -83,7 +83,7 @@ class ImportPath(pr.Base):
def get_defined_names(self, on_import_stmt=False): def get_defined_names(self, on_import_stmt=False):
names = [] names = []
for scope in self.follow(): for scope in self.follow():
if scope is ImportPath.GlobalNamespace: if scope is ImportWrapper.GlobalNamespace:
if not self._is_relative_import(): if not self._is_relative_import():
names += self._get_module_names() names += self._get_module_names()
@@ -216,7 +216,7 @@ class ImportPath(pr.Base):
if self._is_nested_import(): if self._is_nested_import():
scopes.append(self._get_nested_import(scope)) scopes.append(self._get_nested_import(scope))
else: else:
scopes = [ImportPath.GlobalNamespace] scopes = [ImportWrapper.GlobalNamespace]
debug.dbg('after import: %s', scopes) debug.dbg('after import: %s', scopes)
self._evaluator.recursion_detector.pop_stmt() self._evaluator.recursion_detector.pop_stmt()
return scopes return scopes
@@ -424,7 +424,7 @@ def strip_imports(evaluator, scopes):
result = [] result = []
for s in scopes: for s in scopes:
if isinstance(s, pr.Import): if isinstance(s, pr.Import):
result += ImportPath(evaluator, s).follow() result += ImportWrapper(evaluator, s).follow()
else: else:
result.append(s) result.append(s)
return result return result