[flake8-pyi] Add "replace with Self" fix (PYI034)#14217
[flake8-pyi] Add "replace with Self" fix (PYI034)#14217charliermarsh merged 2 commits intoastral-sh:mainfrom
flake8-pyi] Add "replace with Self" fix (PYI034)#14217Conversation
|
| let source_module = if checker.source_type.is_stub() || target_version < (3, 11) { | ||
| "typing_extensions" | ||
| } else { | ||
| "typing" |
There was a problem hiding this comment.
| let source_module = if checker.source_type.is_stub() || target_version < (3, 11) { | |
| "typing_extensions" | |
| } else { | |
| "typing" | |
| let source_module = if checker.source_type.is_stub() || target_version >= (3, 11) { | |
| "typing" | |
| } else { | |
| "typing_extensions" |
There was a problem hiding this comment.
I think we do want to use typing in stubs.
There was a problem hiding this comment.
I don't think Self can be imported from typing on 3.10 and lower, even in stubs. How about if target_version >= (3, 11) { "typing" } else { "typing_extensions" }?
There was a problem hiding this comment.
@InSyncWithFoo is correct -- Self cannot be imported from typing in a .py file or a .pyi file if you want the code to support Python 3.10 or lower (see also: #9761).
In typeshed we always import Self from typing_extensions, because typeshed pretends that typing_extensions is part of the stdlib, and we want our stubs to support Python 3.8-3.13.
There was a problem hiding this comment.
Thanks both! I assumed the semantics were similar to PEP 585.
## Summary See: #14217 (comment). 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 (#9761).
Summary
Resolves #14184.
Test Plan
cargo nextest runandcargo insta test.