[ruff] Fix false positive with unpacked arguments (RUF065) - #26959
Merged
Conversation
HarshalPatel1972
force-pushed
the
fix-ruf065-starred-args
branch
from
July 17, 2026 21:25
c5589e4 to
e843ffb
Compare
ntBre
reviewed
Jul 17, 2026
RUF065 assumes a strict 1:1 positional mapping between format string specifiers and logging arguments. That breaks down when a starred expression (like `*args`) is passed. When we hit a starred argument, the linter gets misaligned and flags unrelated eager conversions. To fix this, we just bail out of the argument loop as soon as we see a starred expression. This stops false positives without breaking legitimate checks for arguments passed *before* the starred one. Fixes astral-sh#26912
HarshalPatel1972
force-pushed
the
fix-ruf065-starred-args
branch
from
July 18, 2026 06:34
e843ffb to
30e903b
Compare
Contributor
Author
|
Ah, thanks for pointing out the new mdtest format! I've migrated the new test cases over to |
|
ruff] Fix false positive with unpacked arguments (RUF065)
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
RUF065 assumes a strict 1:1 positional mapping between format string specifiers (
%s) andloggingarguments. That breaks down entirely when a starred expression (like*args) is passed, because it unpacks an unknown number of items at runtime.When we hit a starred argument, the linter gets misaligned and starts flagging unrelated eager conversions (
str(x)) that don't actually correspond to a%sspecifier. (This one's annoying because it means completely valid logging calls get lint errors).To fix this, we just bail out of the argument loop as soon as we see
arg.is_starred_expr(). I think this is right for the common case, but happy to adjust if there's a better way to handle variadics in this context.Test Plan
Added test scenarios to
RUF065_0.pycovering: