forked from VimPlug/jedi
Some progress in signature understanding
This commit is contained in:
@@ -148,12 +148,15 @@ def _iter_nodes_for_param(param_name, star_count):
|
|||||||
trailer=trailer,
|
trailer=trailer,
|
||||||
)
|
)
|
||||||
for c in contexts:
|
for c in contexts:
|
||||||
yield _remove_given_params(args, c.get_param_names(), star_count)
|
yield _process_params(
|
||||||
|
_remove_given_params(args, c.get_param_names()),
|
||||||
|
star_count,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
assert False
|
assert False
|
||||||
|
|
||||||
|
|
||||||
def _remove_given_params(arguments, param_names, star_count):
|
def _remove_given_params(arguments, param_names):
|
||||||
count = 0
|
count = 0
|
||||||
used_keys = set()
|
used_keys = set()
|
||||||
for key, _ in arguments.unpack():
|
for key, _ in arguments.unpack():
|
||||||
@@ -163,14 +166,16 @@ def _remove_given_params(arguments, param_names, star_count):
|
|||||||
used_keys.add(key)
|
used_keys.add(key)
|
||||||
|
|
||||||
for p in param_names:
|
for p in param_names:
|
||||||
kind = p.get_kind()
|
if count and p.maybe_positional_argument():
|
||||||
if count and kind in (Parameter.POSITIONAL_OR_KEYWORD, Parameter.POSITIONAL_ONLY):
|
|
||||||
count -= 1
|
count -= 1
|
||||||
continue
|
continue
|
||||||
if p.string_name in used_keys \
|
if p.string_name in used_keys and p.maybe_keyword_argument():
|
||||||
and kind in (Parameter.POSITIONAL_OR_KEYWORD, Parameter.KEYWORD_ONLY):
|
|
||||||
continue
|
continue
|
||||||
|
yield p
|
||||||
|
|
||||||
|
|
||||||
|
def _process_params(param_names, star_count):
|
||||||
|
for p in param_names:
|
||||||
# TODO recurse on *args/**kwargs
|
# TODO recurse on *args/**kwargs
|
||||||
if star_count == 1 and p.maybe_positional_argument():
|
if star_count == 1 and p.maybe_positional_argument():
|
||||||
yield ParamNameFixedKind(p, Parameter.POSITIONAL_ONLY)
|
yield ParamNameFixedKind(p, Parameter.POSITIONAL_ONLY)
|
||||||
|
|||||||
@@ -98,6 +98,12 @@ def test_tree_signature(Script, environment, code, expected):
|
|||||||
('combined_redirect(simple, simple3)', 'a, b, /, *, a, x: int'),
|
('combined_redirect(simple, simple3)', 'a, b, /, *, a, x: int'),
|
||||||
('combined_redirect(simple2, simple)', 'x, /, *, a, b, c'),
|
('combined_redirect(simple2, simple)', 'x, /, *, a, b, c'),
|
||||||
('combined_redirect(simple3, simple)', 'a, x: int, /, *, a, b, c'),
|
('combined_redirect(simple3, simple)', 'a, x: int, /, *, a, b, c'),
|
||||||
|
|
||||||
|
('combined_redirect(simple, kw)', 'a, b, /, *, a, b, c, **kwargs'),
|
||||||
|
('combined_redirect(kw, simple)', 'a, b, /, *, a, b, c, **kwargs'),
|
||||||
|
|
||||||
|
('combined_lot_of_args(kw, simple4)', '*, b'),
|
||||||
|
('combined_lot_of_args(simple4, kw)', '*, b, c'),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_nested_signatures(Script, environment, combination, expected):
|
def test_nested_signatures(Script, environment, combination, expected):
|
||||||
@@ -105,6 +111,7 @@ def test_nested_signatures(Script, environment, combination, expected):
|
|||||||
def simple(a, b, *, c): ...
|
def simple(a, b, *, c): ...
|
||||||
def simple2(x): ...
|
def simple2(x): ...
|
||||||
def simple3(a, x: int): ...
|
def simple3(a, x: int): ...
|
||||||
|
def simple4(a, b, x: int): ...
|
||||||
def a(a, b, *args): ...
|
def a(a, b, *args): ...
|
||||||
def kw(a, b, *, c, **kwargs): ...
|
def kw(a, b, *, c, **kwargs): ...
|
||||||
def akw(a, b, *args, **kwargs): ...
|
def akw(a, b, *args, **kwargs): ...
|
||||||
@@ -113,10 +120,10 @@ def test_nested_signatures(Script, environment, combination, expected):
|
|||||||
return lambda *args, **kwargs: func(1)
|
return lambda *args, **kwargs: func(1)
|
||||||
def full_redirect(func):
|
def full_redirect(func):
|
||||||
return lambda *args, **kwargs: func(1, *args, **kwargs)
|
return lambda *args, **kwargs: func(1, *args, **kwargs)
|
||||||
def full_redirect(func):
|
|
||||||
return lambda *args, **kwargs: func(, *args, **kwargs)
|
|
||||||
def combined_redirect(func1, func2):
|
def combined_redirect(func1, func2):
|
||||||
return lambda *args, **kwargs: func1(*args) + func2(**kwargs)
|
return lambda *args, **kwargs: func1(*args) + func2(**kwargs)
|
||||||
|
def combined_lot_of_args(func1, func2):
|
||||||
|
return lambda *args, **kwargs: func1(1, 2, 3, 4, *args) + func2(a=3, x=1, y=1, **kwargs)
|
||||||
''')
|
''')
|
||||||
code += 'z = ' + combination + '\nz('
|
code += 'z = ' + combination + '\nz('
|
||||||
sig, = Script(code).call_signatures()
|
sig, = Script(code).call_signatures()
|
||||||
|
|||||||
Reference in New Issue
Block a user