What is typing_extensions and when to use it
maintyping_extensions is a library that complements the standard-library typing module. It provides runtime support for type hints specified in PEPs (Python Enhancement Proposals).
Use typing_extensions for two main purposes:
- Backporting features: Use new type system features (like
typing.TypeGuard) on older Python versions that do not yet have them in the standard library. - Experimentation: Use type system features proposed in new PEPs before they are officially accepted and added to the
typingmodule in CPython.
Note: typing_extensions re-exports most names from the typing module so you can import everything from one place without worrying about which Python version introduced which object. Exceptions include deprecated or removed items like typing.ByteString, typing.io, and typing.re.