Skip to content

Commit db17860

Browse files
authored
Fix false positive for positional-only-arguments-expected when a function contains both a positional-only parameter that has a default value, and **kwargs. (#8556)
1 parent b63c8a1 commit db17860

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix false positive for ``positional-only-arguments-expected`` when a function contains both a positional-only parameter that has a default value, and ``**kwargs``.
2+
3+
Closes #8555

pylint/checkers/method_args.py

+2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ def _check_positional_only_arguments_expected(self, node: nodes.Call) -> None:
111111
and inferred_func.args.posonlyargs
112112
):
113113
return
114+
if inferred_func.args.kwarg:
115+
return
114116
pos_args = [a.name for a in inferred_func.args.posonlyargs]
115117
kws = [k.arg for k in node.keywords if k.arg in pos_args]
116118
if not kws:

tests/functional/p/positional_only_arguments_expected.py

+18
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,21 @@ def nihon(self, a, r, i, /, cheese=False):
1616
cake.nihon(1, r=2, i=3) # [positional-only-arguments-expected]
1717
cake.nihon(a=1, r=2, i=3) # [positional-only-arguments-expected]
1818
cake.nihon(1, r=2, i=3, cheese=True) # [positional-only-arguments-expected]
19+
20+
21+
def function_with_kwargs(apple, banana="Yellow banana", /, **kwargs):
22+
"""
23+
Calling this function with the `banana` keyword should not emit
24+
`positional-only-arguments-expected` since it is added to `**kwargs`.
25+
26+
>>> function_with_kwargs("Red apple", banana="Green banana")
27+
>>> "Red apple"
28+
>>> "Yellow banana"
29+
>>> {"banana": "Green banana"}
30+
"""
31+
print(apple)
32+
print(banana)
33+
print(kwargs)
34+
35+
36+
function_with_kwargs("Red apple", banana="Green banana")

0 commit comments

Comments
 (0)