-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flake8-pyi
] Add "replace with Self
" fix (PYI034
)
#14217
Conversation
|
let source_module = if checker.source_type.is_stub() || target_version < (3, 11) { | ||
"typing_extensions" | ||
} else { | ||
"typing" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we do want to use typing
in stubs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks both! I assumed the semantics were similar to PEP 585.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
## 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 run
andcargo insta test
.