[ruff
] Validate arguments before offering a fix (RUF056
)
#18631
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #18628 by avoiding a fix if there are "unknown" arguments, including any keyword arguments and more than the expected 2 positional arguments.
I'm a bit on the fence here because it also seems reasonable to avoid a diagnostic at all. Especially in the final test case I added (
not my_dict.get(default=False)
), the hint suggesting to removedefault=False
seems pretty misleading. At the same time, I guess the diagnostic at least calls attention to the call site, which could help to fix the missing argument bug too.As I commented on the issue, I double-checked that keyword arguments are invalid as far back as Python 3.8, even though the positional-only marker was only added to the docs in 3.12 (link is to 3.11, showing its absence).
Test Plan
New tests derived from the bug report
Stabilization
This was planned to be stabilized in 0.12, and the bug is less severe than some others, but if there's nobody opposed, I will plan not to stabilize this one for now.