mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 14:54:47 +08:00
Deal better with some error nodes
This commit is contained in:
@@ -185,6 +185,7 @@ class CallDetails(object):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
print(args)
|
||||||
is_kwarg = False
|
is_kwarg = False
|
||||||
for i, (star_count, key_start, had_equal) in enumerate(args):
|
for i, (star_count, key_start, had_equal) in enumerate(args):
|
||||||
is_kwarg |= had_equal | (star_count == 2)
|
is_kwarg |= had_equal | (star_count == 2)
|
||||||
@@ -225,6 +226,8 @@ class CallDetails(object):
|
|||||||
|
|
||||||
def _iter_arguments(nodes, position):
|
def _iter_arguments(nodes, position):
|
||||||
def remove_after_pos(name):
|
def remove_after_pos(name):
|
||||||
|
if name.type != 'name':
|
||||||
|
return None
|
||||||
return name.value[:position[1] - name.start_pos[1]]
|
return name.value[:position[1] - name.start_pos[1]]
|
||||||
|
|
||||||
# Returns Generator[Tuple[star_count, Optional[key_start: str], had_equal]]
|
# Returns Generator[Tuple[star_count, Optional[key_start: str], had_equal]]
|
||||||
@@ -235,6 +238,7 @@ def _iter_arguments(nodes, position):
|
|||||||
return
|
return
|
||||||
|
|
||||||
previous_node_yielded = False
|
previous_node_yielded = False
|
||||||
|
print(nodes_before)
|
||||||
for i, node in enumerate(nodes_before):
|
for i, node in enumerate(nodes_before):
|
||||||
if node.type == 'argument':
|
if node.type == 'argument':
|
||||||
previous_node_yielded = True
|
previous_node_yielded = True
|
||||||
@@ -246,7 +250,7 @@ def _iter_arguments(nodes, position):
|
|||||||
else:
|
else:
|
||||||
yield 0, remove_after_pos(first), True
|
yield 0, remove_after_pos(first), True
|
||||||
elif first in ('*', '**'):
|
elif first in ('*', '**'):
|
||||||
yield len(first), remove_after_pos(second), ''
|
yield len(first.value), remove_after_pos(second), False
|
||||||
else:
|
else:
|
||||||
# Must be a Comprehension
|
# Must be a Comprehension
|
||||||
first_leaf = node.get_first_leaf()
|
first_leaf = node.get_first_leaf()
|
||||||
@@ -254,6 +258,9 @@ def _iter_arguments(nodes, position):
|
|||||||
yield 0, remove_after_pos(first_leaf), False
|
yield 0, remove_after_pos(first_leaf), False
|
||||||
else:
|
else:
|
||||||
yield 0, None, False
|
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 == ',':
|
elif isinstance(node, tree.PythonLeaf) and node.value == ',':
|
||||||
if not previous_node_yielded:
|
if not previous_node_yielded:
|
||||||
yield 0, '', False
|
yield 0, '', False
|
||||||
@@ -339,7 +346,7 @@ def get_call_signature_details(module, position):
|
|||||||
)
|
)
|
||||||
if result is not None:
|
if result is not None:
|
||||||
return result
|
return result
|
||||||
additional_children.append(n)
|
additional_children.insert(0, n)
|
||||||
|
|
||||||
if node.type == 'trailer' and node.children[0] == '(':
|
if node.type == 'trailer' and node.children[0] == '(':
|
||||||
leaf = node.get_previous_leaf()
|
leaf = node.get_previous_leaf()
|
||||||
|
|||||||
@@ -451,6 +451,8 @@ code4 = 'def i(u, /, v, *args, x=1, y, **kwargs): pass'
|
|||||||
(code3, 'h(a,b,args=', None),
|
(code3, 'h(a,b,args=', None),
|
||||||
(code3, 'h(u,v=', 1),
|
(code3, 'h(u,v=', 1),
|
||||||
(code3, 'h(u=', None),
|
(code3, 'h(u=', None),
|
||||||
|
#(code3, 'h(u,*xxx', 1),
|
||||||
|
#(code3, 'h(u,*[]', 1),
|
||||||
|
|
||||||
# *args, **kwargs
|
# *args, **kwargs
|
||||||
(code4, 'i(a,b,c,d', 2),
|
(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=5,y=4,x=3,', 5),
|
||||||
(code4, 'i(a,b,c,d=4,', 3),
|
(code4, 'i(a,b,c,d=4,', 3),
|
||||||
(code4, 'i(a,b,c,x=1,d=,', 4),
|
(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):
|
def test_signature_index(skip_pre_python38, Script, code, call, expected_index):
|
||||||
sig, = Script(code + '\n' + call).call_signatures()
|
sig, = Script(code + '\n' + call).call_signatures()
|
||||||
index = sig.index
|
index = sig.index
|
||||||
|
print(call)
|
||||||
assert expected_index == index
|
assert expected_index == index
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user