From dca594f89fe0f892f8f939e09d799d2974a811d7 Mon Sep 17 00:00:00 2001 From: GiGaGon <107241144+MeGaGiGaGon@users.noreply.github.com> Date: Sat, 12 Jul 2025 10:39:25 -0700 Subject: [PATCH] [`pyupgrade`] Make example error out-of-the-box (`UP040`) (#19296) ## Summary Part of #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 N/A, no functionality/tests affected --- .../rules/pyupgrade/rules/pep695/non_pep695_type_alias.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_type_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_type_alias.rs index 5fb8937abf..e14c5c8632 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_type_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/non_pep695_type_alias.rs @@ -40,12 +40,18 @@ use super::{ /// /// ## Example /// ```python +/// from typing import Annotated, TypeAlias, TypeAliasType +/// from annotated_types import Gt +/// /// ListOfInt: TypeAlias = list[int] /// PositiveInt = TypeAliasType("PositiveInt", Annotated[int, Gt(0)]) /// ``` /// /// Use instead: /// ```python +/// from typing import Annotated +/// from annotated_types import Gt +/// /// type ListOfInt = list[int] /// type PositiveInt = Annotated[int, Gt(0)] /// ```