diff --git a/jedi/api/helpers.py b/jedi/api/helpers.py index 17134033..59675c38 100644 --- a/jedi/api/helpers.py +++ b/jedi/api/helpers.py @@ -254,7 +254,7 @@ def _iter_arguments(nodes, position): yield 0, remove_after_pos(first_leaf), False else: yield 0, None, False - elif node == ',': + elif isinstance(node, tree.PythonLeaf) and node.value == ',': if not previous_node_yielded: yield 0, '', False previous_node_yielded = False @@ -294,7 +294,7 @@ def _get_index_and_key(nodes, position): return nodes_before.count(','), key_str -def _get_call_signature_details_from_error_node(node, position): +def _get_call_signature_details_from_error_node(node, additional_children, position): for index, element in reversed(list(enumerate(node.children))): # `index > 0` means that it's a trailer and not an atom. if element == '(' and element.end_pos <= position and index > 0: @@ -305,7 +305,7 @@ def _get_call_signature_details_from_error_node(node, position): if name is None: continue if name.type == 'name' or name.parent.type in ('trailer', 'atom'): - return CallDetails(element, children, position) + return CallDetails(element, children + additional_children, position) def get_call_signature_details(module, position): @@ -330,11 +330,16 @@ def get_call_signature_details(module, position): # makes it feel strange to have a call signature. return None - for n in node.children[::-1]: - if n.start_pos < position and n.type == 'error_node': - result = _get_call_signature_details_from_error_node(n, position) - if result is not None: - return result + additional_children = [] + for n in reversed(node.children): + if n.start_pos < position: + if n.type == 'error_node': + result = _get_call_signature_details_from_error_node( + n, additional_children, position + ) + if result is not None: + return result + additional_children.append(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 d0d910a0..c26ecccf 100644 --- a/test/test_api/test_call_signatures.py +++ b/test/test_api/test_call_signatures.py @@ -457,13 +457,13 @@ code4 = 'def i(u, /, v, *args, x=1, y, **kwargs): pass' (code4, 'i(a,b,c,d,e', 2), (code4, 'i(a,b,c,d,e=', 5), (code4, 'i(a,b,c,d,e=3', 5), - #(code4, 'i(a,b,c,d=,x=', 3), + (code4, 'i(a,b,c,d=,x=', 3), (code4, 'i(a,b,c,d=5,x=4', 3), (code4, 'i(a,b,c,d=5,x=4,y', 4), (code4, 'i(a,b,c,d=5,x=4,y=3,', 5), (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=2,', 4), + (code4, 'i(a,b,c,x=1,d=,', 4), ] ) def test_signature_index(skip_pre_python38, Script, code, call, expected_index):