-
-
Notifications
You must be signed in to change notification settings - Fork 800
✨ Avoid the unnecessary import of typing_extensions in newer Python versions
#1048
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
Conversation
08f1d06 to
176a06e
Compare
Relevant links: - https://typing-extensions.readthedocs.io/en/latest/index.html#typing_extensions.get_args (since Python 3.8) - https://typing-extensions.readthedocs.io/en/latest/index.html#typing_extensions.get_origin (since Python 3.8) - https://typing-extensions.readthedocs.io/en/latest/index.html#typing_extensions.get_type_hints (since Python 3.?) - https://typing-extensions.readthedocs.io/en/latest/index.html#typing_extensions.Annotated (since Python 3.9) - https://typing-extensions.readthedocs.io/en/latest/index.html#typing_extensions.Literal (since Python 3.8)
176a06e to
ec22523
Compare
typing_extensions in newer Python versions
svlandeg
left a comment
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 for the PR! This makes sense. We do have the check in other places where we're importing things like Literal, though we're checking on v3.8 in those instances. From the link you shared, I see that typing_extensions has an updated definition for 3.8, so it makes sense to only import from typing from 3.9 onwards. Perhaps we should even make that change across the codebase to be consistent.
|
I dont understand that linting error for the |
|
Hm, that's weird. I can have a look sometime later this week if you don't figure it out! |
Looks like this is expected behaviour when importing Meh - I guess we'll just repeat the import code, it's not that big a deal. |
svlandeg
left a comment
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.
Should be good to merge!
tiangolo
left a comment
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.
Nice, thank you! ☕ 🍰
Relevant links:
The reason for this is that typing_extensions is extensive and can cause slowdowns in compiled Python scripts.