Skip to content

[ruff] Fix false positive with unpacked arguments (RUF065) - #26959

Merged
ntBre merged 2 commits into
astral-sh:mainfrom
HarshalPatel1972:fix-ruf065-starred-args
Jul 24, 2026
Merged

[ruff] Fix false positive with unpacked arguments (RUF065)#26959
ntBre merged 2 commits into
astral-sh:mainfrom
HarshalPatel1972:fix-ruf065-starred-args

Conversation

@HarshalPatel1972

@HarshalPatel1972 HarshalPatel1972 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Fixes #26912

RUF065 assumes a strict 1:1 positional mapping between format string specifiers (%s) and logging arguments. 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 %s specifier. (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.py covering:

  • Eager conversion after a starred argument (shouldn't trigger)
  • Eager conversion before a starred argument (still triggers)
  • Multiple starred arguments in the same call
  • Mixed format specifiers before a starred argument

@astral-sh-bot
astral-sh-bot Bot requested a review from ntBre July 17, 2026 21:15
@HarshalPatel1972
HarshalPatel1972 force-pushed the fix-ruf065-starred-args branch from c5589e4 to e843ffb Compare July 17, 2026 21:25
Comment thread crates/ruff_linter/resources/test/fixtures/ruff/RUF065_0.py
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
HarshalPatel1972 force-pushed the fix-ruf065-starred-args branch from e843ffb to 30e903b Compare July 18, 2026 06:34
@HarshalPatel1972

Copy link
Copy Markdown
Contributor Author

Ah, thanks for pointing out the new mdtest format! I've migrated the new test cases over to logging-eager-conversion.md and reverted the old RUF065_0.py fixture additions.

@ntBre ntBre added bug Something isn't working rule Implementing or modifying a lint rule preview Related to preview mode features labels Jul 24, 2026

@ntBre ntBre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@astral-sh-bot

astral-sh-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@ntBre ntBre changed the title Fix false positive in RUF065 with unpacked arguments [ruff] Fix false positive with unpacked arguments (RUF065) Jul 24, 2026
@ntBre
ntBre merged commit 71eb5e5 into astral-sh:main Jul 24, 2026
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working preview Related to preview mode features rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RUF065 false positive with unpacked argument

2 participants