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).
This commit is contained in:
Charlie Marsh 2024-11-09 13:17:36 -05:00 committed by GitHub
parent ce3af27f59
commit 1279c20ee1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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<Edit> {
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"