From 1279c20ee1998f910cfc36f44f3dcad0aff9e277 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sat, 9 Nov 2024 13:17:36 -0500 Subject: [PATCH] Avoid using `typing.Self` in stub files pre-Python 3.11 (#14230) ## Summary See: https://github.com/astral-sh/ruff/pull/14217#discussion_r1835340869. This means we're recommending `typing_extensions` in non-stubs pre-3.11, which may not be a valid project dependency, but that's a separate issue (https://github.com/astral-sh/ruff/issues/9761). --- .../src/rules/flake8_pyi/rules/non_self_return_type.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/non_self_return_type.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/non_self_return_type.rs index d5d70b02500d8..a0b772e8b51e3 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/non_self_return_type.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/non_self_return_type.rs @@ -191,7 +191,7 @@ fn add_diagnostic( /// Return an [`Edit`] that imports `typing.Self` from `typing` or `typing_extensions`. fn import_self(checker: &Checker, range: TextRange) -> Option { let target_version = checker.settings.target_version.as_tuple(); - let source_module = if checker.source_type.is_stub() || target_version >= (3, 11) { + let source_module = if target_version >= (3, 11) { "typing" } else { "typing_extensions"