Skip to content

[pyupgrade] Avoid converting format calls with more kinds of side effects (UP032)#25484

Merged
ntBre merged 3 commits into
astral-sh:mainfrom
anishgirianish:up032-repeated-side-effects
Jun 2, 2026
Merged

[pyupgrade] Avoid converting format calls with more kinds of side effects (UP032)#25484
ntBre merged 3 commits into
astral-sh:mainfrom
anishgirianish:up032-repeated-side-effects

Conversation

@anishgirianish
Copy link
Copy Markdown
Contributor

Summary

Fixes part of #15874: UP032 unsoundly converted str.format calls that repeat a side-effecting argument. The check only
caught calls, so a repeated d[k] or walrus slipped through. Switch it to contains_effect.

Test Plan

New mdtest at crates/ruff_linter/resources/mdtest/pyupgrade/f-string.md.

@astral-sh-bot astral-sh-bot Bot requested a review from ntBre May 30, 2026 16:20
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented May 30, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@ntBre ntBre changed the title [pyupgrade] Don't convert repeated args with non-call side effects (UP032) [pyupgrade] Don't convert repeated args with non-call side effects (UP032) Jun 1, 2026
@ntBre ntBre added bug Something isn't working fixes Related to suggested fixes for violations labels Jun 1, 2026
Copy link
Copy Markdown
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

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

Thank you! I had a couple of minor suggestions that I'd like to get your thoughts on, but this looks reasonable to me.

Comment thread crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs Outdated
Comment thread crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs Outdated
Copy link
Copy Markdown
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

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

Thanks! I pushed a quick simplification now that we're not using the Checker again, but this otherwise still looks great.

@ntBre ntBre changed the title [pyupgrade] Don't convert repeated args with non-call side effects (UP032) [pyupgrade] Avoid converting format calls with more kinds of side effects (UP032) Jun 2, 2026
@ntBre ntBre enabled auto-merge (squash) June 2, 2026 16:57
@ntBre ntBre added rule Implementing or modifying a lint rule and removed fixes Related to suggested fixes for violations labels Jun 2, 2026
@ntBre ntBre merged commit bc52b71 into astral-sh:main Jun 2, 2026
44 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 rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants