-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[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
)
|
crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_type_alias.rs
Outdated
Show resolved
Hide resolved
T: TypeAlias = ( | ||
int | ||
| str | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, all fixes for this rule are unsafe
Aren't they safe in stubs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't they safe in stubs?
hmm, good point. Want to make a followup PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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
.