mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Make nesting of *args/**kwargs possible to understand.
This commit is contained in:
@@ -179,13 +179,16 @@ def _process_params(param_names, star_count=3): # default means both * and **
|
|||||||
for p in param_names:
|
for p in param_names:
|
||||||
if star_count == 1 and p.maybe_positional_argument():
|
if star_count == 1 and p.maybe_positional_argument():
|
||||||
if p.get_kind() == Parameter.VAR_POSITIONAL:
|
if p.get_kind() == Parameter.VAR_POSITIONAL:
|
||||||
yield p
|
for param_names in _iter_nodes_for_param(p, star_count=1):
|
||||||
|
for p in param_names:
|
||||||
|
yield p
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
yield p
|
||||||
else:
|
else:
|
||||||
yield ParamNameFixedKind(p, Parameter.POSITIONAL_ONLY)
|
yield ParamNameFixedKind(p, Parameter.POSITIONAL_ONLY)
|
||||||
elif star_count == 2 and p.maybe_keyword_argument():
|
elif star_count == 2 and p.maybe_keyword_argument():
|
||||||
if p.get_kind() == Parameter.VAR_KEYWORD:
|
if p.get_kind() == Parameter.VAR_KEYWORD:
|
||||||
yield p
|
|
||||||
continue
|
|
||||||
itered = list(_iter_nodes_for_param(p, star_count=2))
|
itered = list(_iter_nodes_for_param(p, star_count=2))
|
||||||
if not itered:
|
if not itered:
|
||||||
# We were not able to resolve kwargs.
|
# We were not able to resolve kwargs.
|
||||||
|
|||||||
@@ -104,6 +104,11 @@ def test_tree_signature(Script, environment, code, expected):
|
|||||||
|
|
||||||
('combined_lot_of_args(kw, simple4)', '*, b'),
|
('combined_lot_of_args(kw, simple4)', '*, b'),
|
||||||
('combined_lot_of_args(simple4, kw)', '*, b, c, **kwargs'),
|
('combined_lot_of_args(simple4, kw)', '*, b, c, **kwargs'),
|
||||||
|
|
||||||
|
('combined_redirect(combined_redirect(simple2, simple4), combined_redirect(kw, simple5))',
|
||||||
|
'x, /, *, y'),
|
||||||
|
('combined_redirect(combined_redirect(simple4, simple2), combined_redirect(simple5, kw))',
|
||||||
|
'a, b, x: int, /, *, a, b, c, **kwargs'),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_nested_signatures(Script, environment, combination, expected):
|
def test_nested_signatures(Script, environment, combination, expected):
|
||||||
@@ -112,6 +117,7 @@ def test_nested_signatures(Script, environment, combination, expected):
|
|||||||
def simple2(x): ...
|
def simple2(x): ...
|
||||||
def simple3(a, x: int): ...
|
def simple3(a, x: int): ...
|
||||||
def simple4(a, b, x: int): ...
|
def simple4(a, b, x: int): ...
|
||||||
|
def simple5(y): ...
|
||||||
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): ...
|
||||||
|
|||||||
Reference in New Issue
Block a user