[pyupgrade] Don't introduce invalid syntax when upgrading old-style type aliases with parenthesized multiline values (UP040) - #16026
Conversation
pyupgrade] Don't introduce invalid syntax when upgrading old-style type aliases (UP040)
pyupgrade] Don't introduce invalid syntax when upgrading old-style type aliases (UP040)pyupgrade] Don't introduce invalid syntax when upgrading old-style type aliases with parenthesized multiline values (UP040)
|
| T: TypeAlias = ( | ||
| int | ||
| | str | ||
| ) |
There was a problem hiding this comment.
This might be a good test case to add:
T: TypeAlias = ( # This comment should not make the fix unsafe
int | str
)There was a problem hiding this comment.
Thanks! However, all fixes for this rule are unsafe (because you can't use PEP-695 type aliases as the second argument in isinstance() calls, whereas you can with old-style type aliases that use TypeAlias)
There was a problem hiding this comment.
However, all fixes for this rule are unsafe
Aren't they safe in stubs?
There was a problem hiding this comment.
Aren't they safe in stubs?
hmm, good point. Want to make a followup PR?
There was a problem hiding this comment.
Sure. I'm ready whenever you are.
|
Sorry about that! Thanks for the quick fix! I don't have anything to add on top of the other reviews, LGTM. |
dc7f8d5 to
06e4503
Compare
…ffect applicability (`UP040`) (#16027) ## Summary Follow-up to #16026. Previously, the fix for this would be marked as unsafe, even though all comments are preserved: ```python # .pyi T: TypeAlias = ( # Comment int | str ) ``` Now it is safe: comments within the parenthesized range no longer affect applicability. ## Test Plan `cargo nextest run` and `cargo insta test`. --------- Co-authored-by: Dylan <53534755+dylwil3@users.noreply.github.com>
Summary
We previously autofixed this:
to this:
When we should be autofixing it to this:
This PR fixes the bug. Closes #16023
Test Plan
New fixture added that repros the issue on
main.