-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Support conditionally importing from typing_extensions #14220
Comments
Is there a need to support this idiom? The |
Spelling things with if sys.version_info checks works well; I'm fine with a won't fix here |
Some packages might prefer to only require the extra dependency if a user is installing the package on an older version of Python, so as to keep third-party dependencies to an absolute minimum where possible. I think this practice is relatively common. Having said that, I agree with @hauntsaninja that the |
@gamecss, please don't post duplicate comments in multiple places. Copying and pasting the reply I left you in #16903:
|
This code tries to import
TypeAlias
fromtyping
if possible and falls back totyping_extensions
if it isn't available (e.g. on Python 3.8):Mypy doesn't actually support this as expected in older Python versions that are missing the definition in
typing
. They will just get anAny
value, and the except block has no significance.Perhaps the import from
typing_extensions
should take precedence? Or can we at least generate a more specific error about this?A possible workaround is to flip the order of the imports.
This probably affects any feature that requires an import of a backported definition from
typing_extensions
.Related issue: #14219
The text was updated successfully, but these errors were encountered: