Skip to content

False positive for keyword-arg-before-vararg with positional-only parameter #8570

@mbyrnepr2

Description

@mbyrnepr2

Bug description

keyword-arg-before-vararg is emitted by Pylint for the following a.py where we have a positional-only parameter with a default value followed by *args:

def name(param1=True, /, *args): ...

This is a false positive because the keyword-arg-before-vararg checker exists to warn us about function signatures that can lead to TypeError: name() got multiple values for argument "param1" when this function would be called with the intention of passing an arbitrary number of *args together with a keyword-argument for param1.
However, in this case, we have the following, since it isn't possible to pass a positional-only parameter as a keyword anyway:

Traceback (most recent call last):
  File "/Users/markbyrne/programming/a.py", line 3, in <module>
    name1(1, 2, 3, 4, 5, param1=False)
TypeError: name1() got some positional-only arguments passed as keyword arguments: 'param1'

I propose suppressing the warning in this situation.

For further context on keyword-arg-before-vararg see comment.

Configuration

No response

Command used

pylint a.py

Pylint output

a.py:1:0: W1113: Keyword argument before variable positional arguments list in the definition of name1 function (keyword-arg-before-vararg)

Expected behavior

No warning is emitted.

Pylint version

pylint 3.0.0b1
astroid 2.16.0dev0
Python 3.10.4

OS / Environment

No response

Additional dependencies

No response

Metadata

Metadata

Assignees

Labels

False Positive 🦟A message is emitted but nothing is wrong with the code

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions