Skip to content

[ruff] Fix RUF065 false positive after unpacked argument - #27020

Closed
bhrugusetlur-art wants to merge 1 commit into
astral-sh:mainfrom
bhrugusetlur-art:ruf065-starred-arg
Closed

[ruff] Fix RUF065 false positive after unpacked argument#27020
bhrugusetlur-art wants to merge 1 commit into
astral-sh:mainfrom
bhrugusetlur-art:ruf065-starred-arg

Conversation

@bhrugusetlur-art

Copy link
Copy Markdown

Fixes #26912

Summary

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 the case in the issue:

logging.warning("%s%s%s%s %r", *"1234", str(5))

*"1234" consumes all four %s specifiers, so str(5) lands on %r. The rule instead paired it with a %s and reported the str() as unnecessary — applying that suggestion changes the logged output from '5' to 5.

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.py covering both directions — conversions after an unpacking (no longer flagged) and before one (still flagged). Note these are placed above the def 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_linter passes (2811 tests) and cargo clippy -p ruff_linter --all-targets -- -D warnings is clean.

@astral-sh-bot
astral-sh-bot Bot requested a review from ntBre July 20, 2026 19:28
`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
@ntBre

ntBre commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Thanks, but this looks like a duplicate of #26959.

@ntBre ntBre closed this Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RUF065 false positive with unpacked argument

2 participants