Repository navigation
[pyupgrade] Preserve grouping in multiline UP040 fixes - #28164
Merged
ntBre merged 3 commits intoSep 15, 2026
Merged
Conversation
pyupgrade] Preserve grouping in multiline UP040 fixes
This was referenced Aug 31, 2026
Contributor
|
Could you check if the |
|
Rewriting a `TypeAliasType` assignment to a `type` statement drops the
call, so a value that relied on the call's parentheses to span several
lines became a syntax error:
LongAlias = TypeAliasType(
"LongAlias",
int
| str
)
Build the right-hand side with `unwrapped_call_argument`, which restores
the parentheses when the argument needs them and leaves the argument's
own parentheses alone when it already has them.
Fixes astral-sh#28102
fredrikblau
force-pushed
the
fix/28102-up040-multiline-alias
branch
from
September 4, 2026 22:57
1682f12 to
9cebbae
Compare
Contributor
Author
Yes — unwrapped_call_argument works here, thanks. I've swapped the rule over to it. |
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.
Summary
UP040fixes for multilineTypeAliasTypeunions could remove the grouping supplied by the call syntax, producing invalid Python. Multiline binary and boolean expressions are now parenthesized in the generatedtypestatement.Fixes #28102
Test Plan
INSTA_FORCE_PASS=1 INSTA_UPDATE=always cargo test -p ruff_linter --lib rules::pyupgradecargo fmt --all -- --checkgit diff --check