Skip to content

Commit

Permalink
Fix false positive for positional-only-arguments-expected when a …
Browse files Browse the repository at this point in the history
…function contains both a positional-only parameter that has a default value, and ``**kwargs``. (#8556)
  • Loading branch information
mbyrnepr2 authored Apr 10, 2023
1 parent b63c8a1 commit db17860
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/8555.false_positive
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix false positive for ``positional-only-arguments-expected`` when a function contains both a positional-only parameter that has a default value, and ``**kwargs``.

Closes #8555
2 changes: 2 additions & 0 deletions pylint/checkers/method_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def _check_positional_only_arguments_expected(self, node: nodes.Call) -> None:
and inferred_func.args.posonlyargs
):
return
if inferred_func.args.kwarg:
return
pos_args = [a.name for a in inferred_func.args.posonlyargs]
kws = [k.arg for k in node.keywords if k.arg in pos_args]
if not kws:
Expand Down
18 changes: 18 additions & 0 deletions tests/functional/p/positional_only_arguments_expected.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,21 @@ def nihon(self, a, r, i, /, cheese=False):
cake.nihon(1, r=2, i=3) # [positional-only-arguments-expected]
cake.nihon(a=1, r=2, i=3) # [positional-only-arguments-expected]
cake.nihon(1, r=2, i=3, cheese=True) # [positional-only-arguments-expected]


def function_with_kwargs(apple, banana="Yellow banana", /, **kwargs):
"""
Calling this function with the `banana` keyword should not emit
`positional-only-arguments-expected` since it is added to `**kwargs`.
>>> function_with_kwargs("Red apple", banana="Green banana")
>>> "Red apple"
>>> "Yellow banana"
>>> {"banana": "Green banana"}
"""
print(apple)
print(banana)
print(kwargs)


function_with_kwargs("Red apple", banana="Green banana")

0 comments on commit db17860

Please sign in to comment.