mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-15 18:17:07 +08:00
Refactoring: Make Import.get_all_import_names return NameParts.
This commit is contained in:
@@ -28,13 +28,13 @@ def get_on_import_stmt(evaluator, user_context, user_stmt, is_like_search=False)
|
||||
import_names = user_stmt.get_all_import_names()
|
||||
kill_count = -1
|
||||
cur_name_part = None
|
||||
for i in import_names:
|
||||
if user_stmt.alias == i:
|
||||
for name in import_names:
|
||||
if user_stmt.alias_name_part == name:
|
||||
continue
|
||||
for name_part in i.names:
|
||||
if name_part.end_pos >= user_context.position:
|
||||
|
||||
if name.end_pos >= user_context.position:
|
||||
if not cur_name_part:
|
||||
cur_name_part = name_part
|
||||
cur_name_part = name
|
||||
kill_count += 1
|
||||
|
||||
context = user_context.get_context()
|
||||
|
||||
@@ -70,11 +70,10 @@ def usages(evaluator, definitions, mods):
|
||||
if isinstance(stmt, pr.Import):
|
||||
count = 0
|
||||
imps = []
|
||||
for i in stmt.get_all_import_names():
|
||||
for name_part in i.names:
|
||||
for name in stmt.get_all_import_names():
|
||||
count += 1
|
||||
if unicode(name_part) == search_name:
|
||||
imps.append((count, name_part))
|
||||
if unicode(name) == search_name:
|
||||
imps.append((count, name))
|
||||
|
||||
for used_count, name_part in imps:
|
||||
i = imports.ImportWrapper(evaluator, stmt, kill_count=count - used_count,
|
||||
|
||||
@@ -323,7 +323,7 @@ class Evaluator(object):
|
||||
if stmt.alias_name_part == call_path[0]:
|
||||
return [call_path[0]]
|
||||
|
||||
names = stmt.get_all_import_name_parts()
|
||||
names = stmt.get_all_import_names()
|
||||
# Filter names that are after our Name
|
||||
removed_names = len(names) - names.index(call_path[0]) - 1
|
||||
i = imports.ImportWrapper(self, stmt, kill_count=removed_names)
|
||||
|
||||
@@ -226,7 +226,7 @@ def get_module_name_parts(module):
|
||||
for stmt_or_import in statements_or_imports:
|
||||
if isinstance(stmt_or_import, pr.Import):
|
||||
for name in stmt_or_import.get_all_import_names():
|
||||
name_parts.update(name.names)
|
||||
name_parts.add(name)
|
||||
else:
|
||||
# Running this ensures that all the expression lists are generated
|
||||
# and the parents are all set. (Important for Lambdas) Howeer, this
|
||||
|
||||
@@ -831,20 +831,6 @@ class Import(Simple):
|
||||
return [self.namespace]
|
||||
|
||||
def get_all_import_names(self):
|
||||
n = []
|
||||
if self.from_ns:
|
||||
n.append(self.from_ns)
|
||||
if self.namespace:
|
||||
n.append(self.namespace)
|
||||
if self.alias:
|
||||
n.append(self.alias)
|
||||
return n
|
||||
|
||||
def get_all_import_name_parts(self):
|
||||
"""
|
||||
TODO refactor and use this method, because NamePart will not exist in
|
||||
the future.
|
||||
"""
|
||||
n = []
|
||||
if self.from_ns:
|
||||
n += self.from_ns.names
|
||||
|
||||
Reference in New Issue
Block a user