diff --git a/jedi/api/helpers.py b/jedi/api/helpers.py index 59675c38..7054c225 100644 --- a/jedi/api/helpers.py +++ b/jedi/api/helpers.py @@ -185,6 +185,7 @@ class CallDetails(object): else: return None + print(args) is_kwarg = False for i, (star_count, key_start, had_equal) in enumerate(args): is_kwarg |= had_equal | (star_count == 2) @@ -225,6 +226,8 @@ class CallDetails(object): def _iter_arguments(nodes, position): def remove_after_pos(name): + if name.type != 'name': + return None return name.value[:position[1] - name.start_pos[1]] # Returns Generator[Tuple[star_count, Optional[key_start: str], had_equal]] @@ -235,6 +238,7 @@ def _iter_arguments(nodes, position): return previous_node_yielded = False + print(nodes_before) for i, node in enumerate(nodes_before): if node.type == 'argument': previous_node_yielded = True @@ -246,7 +250,7 @@ def _iter_arguments(nodes, position): else: yield 0, remove_after_pos(first), True elif first in ('*', '**'): - yield len(first), remove_after_pos(second), '' + yield len(first.value), remove_after_pos(second), False else: # Must be a Comprehension first_leaf = node.get_first_leaf() @@ -254,6 +258,9 @@ def _iter_arguments(nodes, position): yield 0, remove_after_pos(first_leaf), False else: yield 0, None, False + elif node.type in ('testlist', 'testlist_star_expr'): # testlist is Python 2 + for n in node.children[::2]: + yield 0, remove_after_pos(n), False elif isinstance(node, tree.PythonLeaf) and node.value == ',': if not previous_node_yielded: yield 0, '', False @@ -339,7 +346,7 @@ def get_call_signature_details(module, position): ) if result is not None: return result - additional_children.append(n) + additional_children.insert(0, n) if node.type == 'trailer' and node.children[0] == '(': leaf = node.get_previous_leaf() diff --git a/test/test_api/test_call_signatures.py b/test/test_api/test_call_signatures.py index c26ecccf..1e50b9a7 100644 --- a/test/test_api/test_call_signatures.py +++ b/test/test_api/test_call_signatures.py @@ -451,6 +451,8 @@ code4 = 'def i(u, /, v, *args, x=1, y, **kwargs): pass' (code3, 'h(a,b,args=', None), (code3, 'h(u,v=', 1), (code3, 'h(u=', None), + #(code3, 'h(u,*xxx', 1), + #(code3, 'h(u,*[]', 1), # *args, **kwargs (code4, 'i(a,b,c,d', 2), @@ -464,11 +466,17 @@ code4 = 'def i(u, /, v, *args, x=1, y, **kwargs): pass' (code4, 'i(a,b,c,d=5,y=4,x=3,', 5), (code4, 'i(a,b,c,d=4,', 3), (code4, 'i(a,b,c,x=1,d=,', 4), + + # Error nodes + (code4, 'i(1, [a,b', 1), + (code4, 'i(1, [a,b=,', 2), + (code4, 'i(1, [a!b,', 2), ] ) def test_signature_index(skip_pre_python38, Script, code, call, expected_index): sig, = Script(code + '\n' + call).call_signatures() index = sig.index + print(call) assert expected_index == index