✨ Avoid the unnecessary import of typing_extensions in newer Python versions#1048
✨ Avoid the unnecessary import of typing_extensions in newer Python versions#1048tiangolo merged 8 commits intofastapi:masterfrom
typing_extensions in newer Python versions#1048Conversation
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.
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. |
Relevant links:
The reason for this is that typing_extensions is extensive and can cause slowdowns in compiled Python scripts.