-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[pyupgrade] Make example error out-of-the-box (UP040)
#19296
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
Conversation
|
AlexWaygood
left a comment
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!
| /// | ||
| /// ## Example | ||
| /// ```python | ||
| /// from typing import TypeAlias, TypeAliasType |
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.
Let's add the other missing imports too, even if they're not necessary to trigger UP040 out of the box:
| /// from typing import TypeAlias, TypeAliasType | |
| /// from typing import TypeAlias, TypeAliasType, Annotated | |
| /// from annotated_types import Gt |
And could you also add the missing imports of Annotated and Gt to the Use instead: block below?
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.
Added
…19296) <!-- Thank you for contributing to Ruff/ty! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? (Please prefix with `[ty]` for ty pull requests.) - Does this pull request include references to any relevant issues? --> ## Summary <!-- What's the purpose of the change? What does it do, and why? --> Part of astral-sh#18972 This PR makes [non-pep695-type-alias (UP040)](https://docs.astral.sh/ruff/rules/non-pep695-type-alias/#non-pep695-type-alias-up040)'s example error out-of-the-box. [Old example](https://play.ruff.rs/6beca1be-45cd-4e5a-aafa-6a0584c10d64) ```py ListOfInt: TypeAlias = list[int] PositiveInt = TypeAliasType("PositiveInt", Annotated[int, Gt(0)]) ``` [New example](https://play.ruff.rs/bbad34da-bf07-44e6-9f34-53337e8f57d4) ```py from typing import Annotated, TypeAlias, TypeAliasType from annotated_types import Gt ListOfInt: TypeAlias = list[int] PositiveInt = TypeAliasType("PositiveInt", Annotated[int, Gt(0)]) ``` Imports were also added to the "Use instead" section. ## Test Plan <!-- How was it tested? --> N/A, no functionality/tests affected
Summary
Part of #18972
This PR makes non-pep695-type-alias (UP040)'s example error out-of-the-box.
Old example
New example
Imports were also added to the "Use instead" section.
Test Plan
N/A, no functionality/tests affected