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
Trying to import TypedDict from typing of tpying_extensions fails #3500
Comments
It looks like |
Yes, but my code also has to run on older versions of python.
|
There is not much we can do here. |
|
The issue is that this causes mypy to not understand the There is a precedent with |
@plannigan you can check Python version instead import sys
if sys.version_info >= (3, 8):
from typing import TypedDict, Literal, overload # pylint: disable=no-name-in-module
else:
from typing_extensions import TypedDict, Literal, overload |
To enforce what @vemel said, checking against the version is the preferred method per the documentation. EDIT: @'ed the wrong person |
@vemel's version is the preferred idiom. |
Try to Uninstall the related librarie(s) and install it again. |
This approach is preferred over the try/except one to help MyPy deal with the compatibility quirks according to: * ansible/ansible-lint#915 (comment) * python/typeshed#3500 (comment)
This approach is preferred over the try/except one to help MyPy deal with the compatibility quirks according to: * ansible/ansible-lint#915 (comment) * python/typeshed#3500 (comment)
I have code that runs on Python 3.8 and Python 3.7, but I'd rather not install
typing_extensions
when it isn't need.Code:
Environment:
The above code passes with mypy. However, if you reverse the commented out import statements, mypy fails.
I was able to use this same import pattern successfully for
Protocol
, but for some reason it fails forTypedDict
.The text was updated successfully, but these errors were encountered: