mirror of
https://github.com/davidhalter/jedi.git
synced 2026-02-20 22:48:25 +08:00
fix first tuple assignments
This commit is contained in:
@@ -418,7 +418,7 @@ def related_names(definitions, search_name, mods):
|
|||||||
else:
|
else:
|
||||||
calls = _scan_array(stmt.get_commands(), search_name)
|
calls = _scan_array(stmt.get_commands(), search_name)
|
||||||
for d in stmt.assignment_details:
|
for d in stmt.assignment_details:
|
||||||
calls += _scan_array(d[1], search_name)
|
calls += _scan_array(d[0], search_name)
|
||||||
for call in calls:
|
for call in calls:
|
||||||
names += check_call(call)
|
names += check_call(call)
|
||||||
return names
|
return names
|
||||||
|
|||||||
@@ -483,41 +483,38 @@ def assign_tuples(tup, results, seek_name):
|
|||||||
def eval_results(index):
|
def eval_results(index):
|
||||||
types = []
|
types = []
|
||||||
for r in results:
|
for r in results:
|
||||||
if hasattr(r, "get_exact_index_types"):
|
try:
|
||||||
try:
|
func = r.get_exact_index_types
|
||||||
types += r.get_exact_index_types(index)
|
except AttributeError:
|
||||||
except IndexError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
debug.warning("invalid tuple lookup %s of result %s in %s"
|
debug.warning("invalid tuple lookup %s of result %s in %s"
|
||||||
% (tup, results, seek_name))
|
% (tup, results, seek_name))
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
types += func(index)
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
return types
|
return types
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
if tup.type == pr.Array.NOARRAY:
|
for i, stmt in enumerate(tup):
|
||||||
# Here we have unnessecary braces, which we just remove.
|
# Used in assignments. There is just one call and no other things,
|
||||||
arr = tup.get_only_subelement()
|
# therefore we can just assume, that the first part is important.
|
||||||
if type(arr) == pr.Call:
|
command = stmt.get_commands()[0]
|
||||||
if arr.name.names[-1] == seek_name:
|
|
||||||
result = results
|
|
||||||
else:
|
|
||||||
result = assign_tuples(arr, results, seek_name)
|
|
||||||
else:
|
|
||||||
for i, t in enumerate(tup):
|
|
||||||
# Used in assignments. There is just one call and no other things,
|
|
||||||
# therefore we can just assume, that the first part is important.
|
|
||||||
if len(t) != 1:
|
|
||||||
raise AttributeError('Array length should be 1')
|
|
||||||
t = t[0]
|
|
||||||
|
|
||||||
# Check the left part, if there are still tuples in it or a Call.
|
if tup.type == pr.Array.NOARRAY:
|
||||||
if isinstance(t, pr.Array):
|
|
||||||
# These are "sub"-tuples.
|
# unnessecary braces -> just remove.
|
||||||
result += assign_tuples(t, eval_results(i), seek_name)
|
r = results
|
||||||
else:
|
else:
|
||||||
if t.name.names[-1] == seek_name:
|
r = eval_results(i)
|
||||||
result += eval_results(i)
|
|
||||||
|
# are there still tuples or is it just a Call.
|
||||||
|
if isinstance(command, pr.Array):
|
||||||
|
# These are "sub"-tuples.
|
||||||
|
result += assign_tuples(command, r, seek_name)
|
||||||
|
else:
|
||||||
|
if command.name.names[-1] == seek_name:
|
||||||
|
result += r
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@@ -549,8 +546,8 @@ def follow_statement(stmt, seek_name=None):
|
|||||||
print(seek_name, stmt, stmt.assignment_details)
|
print(seek_name, stmt, stmt.assignment_details)
|
||||||
if len(stmt.get_set_vars()) > 1 and seek_name and stmt.assignment_details:
|
if len(stmt.get_set_vars()) > 1 and seek_name and stmt.assignment_details:
|
||||||
new_result = []
|
new_result = []
|
||||||
for set_vars, op in stmt.assignment_details:
|
for ass_commands, op in stmt.assignment_details:
|
||||||
new_result += assign_tuples(set_vars, result, seek_name)
|
new_result += assign_tuples(ass_commands[0], result, seek_name)
|
||||||
result = new_result
|
result = new_result
|
||||||
return set(result)
|
return set(result)
|
||||||
|
|
||||||
|
|||||||
@@ -630,10 +630,10 @@ class Execution(Executable):
|
|||||||
# Normal arguments (including key arguments).
|
# Normal arguments (including key arguments).
|
||||||
else:
|
else:
|
||||||
if stmt.assignment_detail:
|
if stmt.assignment_detail:
|
||||||
tok, key_arr = stmt.assignment_detail[0]
|
key_arr, op = stmt.assignment_detail[0]
|
||||||
# named parameter
|
# named parameter
|
||||||
if key_arr and isinstance(key_arr[0], pr.Call):
|
if key_arr and isinstance(key_arr[0], pr.Call):
|
||||||
yield tok[0].name, stmt
|
yield op[0].name, stmt
|
||||||
else:
|
else:
|
||||||
yield None, stmt
|
yield None, stmt
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user