Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mbyrnepr2 opened this issue Apr 12, 2023 · 1 comment · Fixed by #8571 or #9093
Closed

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

mbyrnepr2 opened this issue Apr 12, 2023 · 1 comment · Fixed by #8571 or #9093
Assignees
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code
Milestone

Comments

@mbyrnepr2
Copy link
Member

mbyrnepr2 commented Apr 12, 2023

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

@mbyrnepr2 mbyrnepr2 added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Apr 12, 2023
@mbyrnepr2 mbyrnepr2 self-assigned this Apr 12, 2023
@mbyrnepr2 mbyrnepr2 changed the title False positive for keyword-arg-before-vararg and positional-or-keyword parameter False positive for keyword-arg-before-vararg with positional-only parameter Apr 12, 2023
@mbyrnepr2 mbyrnepr2 added this to the 2.17.3 milestone Apr 12, 2023
mbyrnepr2 added a commit that referenced this issue Apr 13, 2023
* Fix false positive for ``keyword-arg-before-vararg`` when a positional-only parameter with a default value precedes ``*args``.

Closes #8570
@mbyrnepr2 mbyrnepr2 added False Positive 🦟 A message is emitted but nothing is wrong with the code and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Apr 13, 2023
@mbyrnepr2
Copy link
Member Author

(Implicit triage since Daniël reviewed the code :)

github-actions bot pushed a commit that referenced this issue Apr 15, 2023
* Fix false positive for ``keyword-arg-before-vararg`` when a positional-only parameter with a default value precedes ``*args``.

Closes #8570

(cherry picked from commit 56fa5dc)
Pierre-Sassoulas pushed a commit that referenced this issue Apr 15, 2023
* Fix false positive for ``keyword-arg-before-vararg`` when a positional-only parameter with a default value precedes ``*args``.

Closes #8570

(cherry picked from commit 56fa5dc)

Co-authored-by: Mark Byrne <31762852+mbyrnepr2@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant