[ruff] Fix RUF065 false positive after unpacked argument - #27020
Closed
bhrugusetlur-art wants to merge 1 commit into
Closed
[ruff] Fix RUF065 false positive after unpacked argument#27020bhrugusetlur-art wants to merge 1 commit into
bhrugusetlur-art wants to merge 1 commit into
Conversation
`logging-eager-conversion` (RUF065) zips `%` format specifiers against
call arguments by position, which assumes each argument supplies exactly
one value. A `*args` unpacking can supply any number, so every argument
after it may line up with a different specifier than its position
suggests.
For `logging.warning("%s%s%s%s %r", *"1234", str(5))` the rule paired
`str(5)` with a `%s` when it actually lands on `%r`, and suggested
removing the `str()` call -- changing the logged output from `'5'` to
`5`.
Stop pairing at the first unpacked argument. Arguments before it are
still positionally aligned, so those remain flagged.
Fixes astral-sh#26912
bhrugusetlur-art
force-pushed
the
ruf065-starred-arg
branch
from
July 20, 2026 19:31
04b7add to
c53678b
Compare
Contributor
|
Thanks, but this looks like a duplicate of #26959. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #26912
Summary
logging-eager-conversion(RUF065) zips%format specifiers against call arguments by position, which assumes each argument supplies exactly one value. A*argsunpacking can supply any number, so every argument after it may line up with a different specifier than its position suggests.For the case in the issue:
*"1234"consumes all four%sspecifiers, sostr(5)lands on%r. The rule instead paired it with a%sand reported thestr()as unnecessary — applying that suggestion changes the logged output from'5'to5.This stops pairing at the first unpacked argument. Arguments before an unpacking are still positionally aligned, so those continue to be flagged and the rule keeps working in the common case.
Test Plan
Added fixture cases to
RUF065_0.pycovering both directions — conversions after an unpacking (no longer flagged) and before one (still flagged). Note these are placed above thedef str(s)shadowing on line 46, since the rule cannot fire once the builtin is shadowed.Verified by regenerating the snapshot with and without the change: the three post-unpacking cases lose their diagnostics, the two pre-unpacking cases keep theirs.
cargo test -p ruff_linterpasses (2811 tests) andcargo clippy -p ruff_linter --all-targets -- -D warningsis clean.