forked from VimPlug/jedi
call_signatures should work on more nested edge cases
This commit is contained in:
@@ -60,24 +60,30 @@ def fast_parent_copy(obj):
|
|||||||
return recursion(obj)
|
return recursion(obj)
|
||||||
|
|
||||||
|
|
||||||
def array_for_pos(stmt, pos, array_types=None):
|
def array_for_pos(stmt, pos):
|
||||||
"""Searches for the array and position of a tuple"""
|
"""
|
||||||
|
Searches for the array and position of a tuple.
|
||||||
|
"""
|
||||||
|
|
||||||
|
#isinstance(arr.parent, pr.StatementElement)
|
||||||
def search_array(arr, pos):
|
def search_array(arr, pos):
|
||||||
|
accepted_types = pr.Array.TUPLE, pr.Array.NOARRAY
|
||||||
if arr.type == 'dict':
|
if arr.type == 'dict':
|
||||||
for stmt in arr.values + arr.keys:
|
for stmt in arr.values + arr.keys:
|
||||||
new_arr, index = array_for_pos(stmt, pos, array_types)
|
new_arr, index = array_for_pos(stmt, pos)
|
||||||
if new_arr is not None:
|
if new_arr is not None:
|
||||||
return new_arr, index
|
return new_arr, index
|
||||||
else:
|
else:
|
||||||
for i, stmt in enumerate(arr):
|
for i, stmt in enumerate(arr):
|
||||||
new_arr, index = array_for_pos(stmt, pos, array_types)
|
new_arr, index = array_for_pos(stmt, pos)
|
||||||
if new_arr is not None:
|
if new_arr is not None:
|
||||||
return new_arr, index
|
return new_arr, index
|
||||||
|
|
||||||
if arr.start_pos < pos <= stmt.end_pos:
|
if arr.start_pos < pos <= stmt.end_pos:
|
||||||
if not array_types or arr.type in array_types:
|
if arr.type in accepted_types and isinstance(arr.parent, pr.Call):
|
||||||
return arr, i
|
return arr, i
|
||||||
if len(arr) == 0 and arr.start_pos < pos < arr.end_pos:
|
if len(arr) == 0 and arr.start_pos < pos < arr.end_pos:
|
||||||
if not array_types or arr.type in array_types:
|
if arr.type in accepted_types and isinstance(arr.parent, pr.Call):
|
||||||
return arr, 0
|
return arr, 0
|
||||||
return None, 0
|
return None, 0
|
||||||
|
|
||||||
@@ -112,10 +118,12 @@ def search_call_signatures(stmt, pos):
|
|||||||
"""
|
"""
|
||||||
# some parts will of the statement will be removed
|
# some parts will of the statement will be removed
|
||||||
stmt = fast_parent_copy(stmt)
|
stmt = fast_parent_copy(stmt)
|
||||||
arr, index = array_for_pos(stmt, pos, [pr.Array.TUPLE, pr.Array.NOARRAY])
|
arr, index = array_for_pos(stmt, pos)
|
||||||
if arr is not None and isinstance(arr.parent, pr.StatementElement):
|
if arr is not None:
|
||||||
call = arr.parent
|
call = arr.parent
|
||||||
while isinstance(call.parent, pr.StatementElement):
|
while isinstance(call.parent, pr.StatementElement):
|
||||||
|
# Go to parent literal/variable until not possible anymore. This
|
||||||
|
# makes it possible to return the whole expression.
|
||||||
call = call.parent
|
call = call.parent
|
||||||
arr.parent.execution = None
|
arr.parent.execution = None
|
||||||
return call if isinstance(call, pr.Call) else None, index, False
|
return call if isinstance(call, pr.Call) else None, index, False
|
||||||
|
|||||||
@@ -161,6 +161,10 @@ class TestCallSignatures(TestCase):
|
|||||||
x = [p.description for p in signatures[0].params]
|
x = [p.description for p in signatures[0].params]
|
||||||
assert x == ['*args']
|
assert x == ['*args']
|
||||||
|
|
||||||
|
def test_additional_brackets(self):
|
||||||
|
s = 'str(('
|
||||||
|
self._run(s, 'str', 0)
|
||||||
|
|
||||||
|
|
||||||
class TestParams(TestCase):
|
class TestParams(TestCase):
|
||||||
def params(self, source, line=None, column=None):
|
def params(self, source, line=None, column=None):
|
||||||
|
|||||||
Reference in New Issue
Block a user