1
0
forked from VimPlug/jedi

many tests and fixes for instance element renamings

This commit is contained in:
David Halter
2012-12-26 22:56:56 +01:00
parent 2534269cce
commit 45c9fe16b8
4 changed files with 71 additions and 11 deletions

View File

@@ -327,7 +327,7 @@ class Script(object):
and self.pos < user_stmt.get_assignment_calls().start_pos: and self.pos < user_stmt.get_assignment_calls().start_pos:
# the search_name might be before `=` # the search_name might be before `=`
definitions = [v for v in user_stmt.set_vars definitions = [v for v in user_stmt.set_vars
if unicode(v) == search_name] if unicode(v.names[-1]) == search_name]
if not isinstance(user_stmt, parsing.Import): if not isinstance(user_stmt, parsing.Import):
# import case is looked at with add_import_name option # import case is looked at with add_import_name option
definitions = dynamic.related_name_add_import_modules(definitions, definitions = dynamic.related_name_add_import_modules(definitions,
@@ -341,7 +341,7 @@ class Script(object):
if isinstance(d, parsing.Module): if isinstance(d, parsing.Module):
names.append(api_classes.RelatedName(d, d)) names.append(api_classes.RelatedName(d, d))
else: else:
names.append(api_classes.RelatedName(d.names[0], d)) names.append(api_classes.RelatedName(d.names[-1], d))
return sorted(set(names), key=lambda x: (x.module_path, x.start_pos), return sorted(set(names), key=lambda x: (x.module_path, x.start_pos),
reverse=True) reverse=True)

View File

@@ -349,12 +349,14 @@ class ArrayInstance(parsing.Base):
def related_names(definitions, search_name, mods): def related_names(definitions, search_name, mods):
def strip_ambiguity(definitions): def compare_array(definitions):
""" `definitions` are being compared by module/start_pos, because
sometimes the id's of the objects change (e.g. executions).
"""
result = [] result = []
for d in definitions: for d in definitions:
if isinstance(d, evaluate.InstanceElement): module = d.get_parent_until()
d = d.var result.append((module, d.start_pos))
result.append(d)
return result return result
def check_call(call): def check_call(call):
@@ -369,11 +371,10 @@ def related_names(definitions, search_name, mods):
for f in follow: for f in follow:
follow_res, search = evaluate.goto(call.parent_stmt, f) follow_res, search = evaluate.goto(call.parent_stmt, f)
follow_res = related_name_add_import_modules(follow_res, search) follow_res = related_name_add_import_modules(follow_res, search)
follow_res = strip_ambiguity(follow_res)
#print follow_res, [d.parent for d in follow_res] compare_follow_res = compare_array(follow_res)
# compare to see if they match # compare to see if they match
if any(r in definitions for r in follow_res): if any(r in compare_definitions for r in compare_follow_res):
scope = call.parent_stmt scope = call.parent_stmt
result.append(api_classes.RelatedName(search, scope)) result.append(api_classes.RelatedName(search, scope))
@@ -395,7 +396,7 @@ def related_names(definitions, search_name, mods):
except AssertionError: except AssertionError:
return False return False
definitions = strip_ambiguity(definitions) compare_definitions = compare_array(definitions)
mods |= set([d.get_parent_until() for d in definitions]) mods |= set([d.get_parent_until() for d in definitions])
names = [] names = []
for m in get_directory_modules_for_name(mods, search_name): for m in get_directory_modules_for_name(mods, search_name):

View File

@@ -113,3 +113,58 @@ class TestClassVar(object):
TestClassVar.class_v TestClassVar.class_v
#< (0,8), (-7, 8) #< (0,8), (-7, 8)
class_v class_v
class TestInstanceVar():
def a(self):
#< 13 (4,13), (0,13)
self._instance_var = 3
def b(self):
#< (-4,13), (0,13)
self._instance_var
# -----------------
# inheritance
# -----------------
class Super(object):
#< 4 (0,4), (23,18), (25,13)
base_class = 1
#< 4 (0,4),
class_var = 1
#< 8 (0,8),
def base_method(self):
#< 13 (0,13), (20,13)
self.base_var = 1
#< 13 (0,13), (29,13)
self.instance_var = 1
#< 8 (0,8),
def just_a_method(self): pass
#< 20 (0,16), (-18,6)
class TestClass(Super):
#< 4 (0,4),
class_var = 1
def x_method(self):
#< (0,18), (2,13), (-23,4)
TestClass.base_class
#< (-2,18), (0,13), (-25,4)
self.base_class
#< (-20,13), (0,13)
self.base_var
#<
TestClass.base_var
#< 13 (5,13), (0,13)
self.instance_var = 3
#< 9 (0,8),
def just_a_method(self):
#< (-5,13), (0,13), (-29,13)
self.instance_var

View File

@@ -88,7 +88,11 @@ def run_related_name_test(script, correct, line_nr):
compare = sorted((r.module_name, r.start_pos[0], r.start_pos[1]) compare = sorted((r.module_name, r.start_pos[0], r.start_pos[1])
for r in result) for r in result)
wanted = [] wanted = []
for pos_tup in literal_eval(correct): if not correct:
positions = []
else:
positions = literal_eval(correct)
for pos_tup in positions:
if type(pos_tup[0]) == str: if type(pos_tup[0]) == str:
# this means that there is a module specified # this means that there is a module specified
wanted.append(pos_tup) wanted.append(pos_tup)