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

Fix false positive for positional-only-arguments-expected #8556

Merged
merged 1 commit into from
Apr 10, 2023
Merged

Fix false positive for positional-only-arguments-expected #8556

merged 1 commit into from
Apr 10, 2023

Conversation

mbyrnepr2
Copy link
Member

Type of Changes

Type
🐛 Bug fix
✨ New feature
🔨 Refactoring
📜 Docs

Description

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

…function contains both a positional-only parameter that has a default value, and ``**kwargs``.

Closes #8555
@codecov
Copy link

codecov bot commented Apr 8, 2023

Codecov Report

Merging #8556 (6e4d89f) into main (82cee37) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #8556   +/-   ##
=======================================
  Coverage   95.90%   95.91%           
=======================================
  Files         174      174           
  Lines       18353    18370   +17     
=======================================
+ Hits        17602    17619   +17     
  Misses        751      751           
Impacted Files Coverage Δ
pylint/checkers/method_args.py 100.00% <100.00%> (ø)
pylint/checkers/variables.py 97.17% <100.00%> (+0.01%) ⬆️

... and 3 files with indirect coverage changes

@mbyrnepr2 mbyrnepr2 added the False Positive 🦟 A message is emitted but nothing is wrong with the code label Apr 8, 2023
@mbyrnepr2 mbyrnepr2 added this to the 2.17.3 milestone Apr 8, 2023
@mbyrnepr2 mbyrnepr2 self-assigned this Apr 8, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Apr 8, 2023

🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉

This comment was generated for commit 6e4d89f

Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice edge case! I find this profoundly weird, and honestly, after reading PEP 570 a couple times, I feel like this could even be reported to CPython as a bug. But even if it's not a bug, it should be a pylint warning on the function def, not a pylint error on the call.

However, I did find this regression, based on the example in PEP 570 ("Semantic Corner Case"). Would you be able to fix and add a test case?

def foo(name, /, **kwds):
    return 'name' in kwds

foo(name=3)

Gives:

TypeError: foo() missing 1 required positional argument: 'name'

main emits:

corner.py:4:0: E3102: `foo()` got some positional-only arguments passed as keyword arguments: 'name' (positional-only-arguments-expected)

PR emits nothing.

@jacobtylerwalls
Copy link
Member

Opened #8558 to track emitting a different message for the original reported case.

@mbyrnepr2
Copy link
Member Author

However, I did find this regression, based on the example in PEP 570 ("Semantic Corner Case"). Would you be able to fix and add a test case?

I don't think this is a regression. The TypeError you've identified is missing 1 required positional argument whereas this checker deals with the TypeError got some positional-only arguments passed as keyword arguments.
This is similar behaviour to the current fix in the sense that name=3 is collected by **kwds and hence the name argument is indeed missing. Here would be a working example:

def foo(name, /, **kwds):
    print(kwds)
    return 'name' in kwds

>>> foo(1, name=3)
>>> {'name': 3}

Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see, makes sense.

@jacobtylerwalls jacobtylerwalls merged commit db17860 into pylint-dev:main Apr 10, 2023
github-actions bot pushed a commit that referenced this pull request Apr 10, 2023
…function contains both a positional-only parameter that has a default value, and ``**kwargs``. (#8556)

(cherry picked from commit db17860)
Pierre-Sassoulas pushed a commit that referenced this pull request Apr 10, 2023
…function contains both a positional-only parameter that has a default value, and ``**kwargs``. (#8556) (#8560)

(cherry picked from commit db17860)

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

Successfully merging this pull request may close these issues.

False positive for positional-only-arguments-expected
3 participants