Skip to content

Conversation

ntBre
Copy link
Contributor

@ntBre ntBre commented Jun 11, 2025

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 remove default=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.

@ntBre ntBre added bug Something isn't working fixes Related to suggested fixes for violations labels Jun 11, 2025
@ntBre ntBre requested a review from MichaReiser June 11, 2025 17:52
Copy link
Contributor

github-actions bot commented Jun 11, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

makes sense. I agree that we could also decide to not raise a diagnostic here because it could hide a more important type checker diagnostic that the keyword argument isn't allowed.

I'm fine with either change/fix.


# `default` is positional-only, so this is invalid
not my_dict.get("key", default=False)
Copy link
Member

Choose a reason for hiding this comment

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

Should we remove the tests on line 152 or change them, or group them?

@ntBre ntBre mentioned this pull request Jun 12, 2025
2 tasks
@ntBre ntBre enabled auto-merge (squash) June 13, 2025 23:04
@ntBre ntBre merged commit e442304 into main Jun 13, 2025
31 checks passed
@ntBre ntBre deleted the brent/fix-ruf056 branch June 13, 2025 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixes Related to suggested fixes for violations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RUF056 ascribes meaning to default and ignores extra arguments
2 participants