diff --git a/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP035.py b/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP035.py index 50e7cbc968..b9c3892a9b 100644 --- a/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP035.py +++ b/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP035.py @@ -110,6 +110,8 @@ from typing_extensions import CapsuleType # UP035 on py313+ only from typing_extensions import deprecated +# UP035 on py313+ only +from typing_extensions import get_type_hints # https://github.com/astral-sh/ruff/issues/15780 from typing_extensions import is_typeddict diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_import.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_import.rs index 765527b6d7..022db39097 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_import.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_import.rs @@ -271,7 +271,7 @@ const TYPING_TO_RE_39: &[&str] = &["Match", "Pattern"]; const TYPING_RE_TO_RE_39: &[&str] = &["Match", "Pattern"]; // Members of `typing_extensions` that were moved to `typing`. -const TYPING_EXTENSIONS_TO_TYPING_39: &[&str] = &["Annotated", "get_type_hints"]; +const TYPING_EXTENSIONS_TO_TYPING_39: &[&str] = &["Annotated"]; // Members of `typing` that were moved _and_ renamed (and thus cannot be // automatically fixed). @@ -373,6 +373,9 @@ const TYPING_EXTENSIONS_TO_TYPING_313: &[&str] = &[ "NoDefault", "ReadOnly", "TypeIs", + // Introduced in Python 3.5, + // but typing_extensions backports features from py313: + "get_type_hints", // Introduced in Python 3.6, // but typing_extensions backports features from py313: "ContextManager", diff --git a/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP035.py.snap b/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP035.py.snap index fb3b19b94a..95c0bee046 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP035.py.snap +++ b/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP035.py.snap @@ -1179,6 +1179,8 @@ UP035.py:111:1: UP035 [*] Import from `warnings` instead: `deprecated` 110 | # UP035 on py313+ only 111 | from typing_extensions import deprecated | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP035 +112 | +113 | # UP035 on py313+ only | = help: Import from `warnings` @@ -1189,5 +1191,25 @@ UP035.py:111:1: UP035 [*] Import from `warnings` instead: `deprecated` 111 |-from typing_extensions import deprecated 111 |+from warnings import deprecated 112 112 | -113 113 | -114 114 | # https://github.com/astral-sh/ruff/issues/15780 +113 113 | # UP035 on py313+ only +114 114 | from typing_extensions import get_type_hints + +UP035.py:114:1: UP035 [*] Import from `typing` instead: `get_type_hints` + | +113 | # UP035 on py313+ only +114 | from typing_extensions import get_type_hints + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP035 +115 | +116 | # https://github.com/astral-sh/ruff/issues/15780 + | + = help: Import from `typing` + +ℹ Safe fix +111 111 | from typing_extensions import deprecated +112 112 | +113 113 | # UP035 on py313+ only +114 |-from typing_extensions import get_type_hints + 114 |+from typing import get_type_hints +115 115 | +116 116 | # https://github.com/astral-sh/ruff/issues/15780 +117 117 | from typing_extensions import is_typeddict