Python typing-extensions Library
Jump to navigation
Jump to search
A Python typing-extensions Library is a Python Library that supplements the Python typing module with additional type hints, some of which are experimental or have been backported to support older versions of Python.
- Context:
- It can enable the use of newer type hinting features in older versions of Python, enhancing cross-version compatibility.
- It can include experimental type hints that might later be incorporated into the standard `typing` module, facilitating early adoption and feedback.
- It can benefit projects that need to maintain compatibility across multiple Python versions but want to leverage the latest advancements in type hinting.
- It can be maintained separately from the Python Standard Library, allowing for quicker updates and incorporation of new type hinting features.
- It can requires separate installation via package managers like pip, unlike the `typing` module which is included with Python.
- It can be recognized and treated specially by static type checkers, ensuring that its type hints are effectively utilized in type checking processes.
- It can include backported changes to `NamedTuple` on Python 3.11 and lower, supporting generic `NamedTuple`s and the `__orig_bases__` attribute.
- It can include various classes and functions like `ParamSpec`, `Protocol`, `ReadOnly`, `Required`, `Self`, `TypeAlias`, `TypeAliasType`, `TypeGuard`, and `TypedDict`, each providing specific functionality to enhance Python's typing capabilities.
- ...
- Example(s):
- The latest version of `typing_extensions` as of December 10, 2023, is 4.9.0, which includes features like the `ReadOnly` qualifier and improvements to `TypedDict`.
- ...
- Counter-Example(s):
- See: Type Hinting, Static Type Checking, Python Software Foundation License, Python Enhancement Proposal, Semantic Versioning, Static Type Checking, Python Enhancement Proposal, Semantic Versioning, Python Software Foundation License.
References
2024
- (PyPI, 2024) ⇒ PyPI. (2024). “Typing Extensions.” In: PyPI. [1]
- QUOTE: The `typing_extensions` module serves two related purposes:
- Enable use of new type system features on older Python versions. For example, typing.TypeGuard is new in Python 3.10, but typing_extensions allows users on previous Python versions to use it too.
- QUOTE: The `typing_extensions` module serves two related purposes:
Enable experimentation with new type system PEPs before they are accepted and added to the typing module.
typing_extensions is treated specially by static type checkers such as mypy and pyright. Objects defined in typing_extensions are treated the same way as equivalent forms in typing.
typing_extensions uses Semantic Versioning. The major version will be incremented only for backwards-incompatible changes. Therefore, it's safe to depend on typing_extensions like this: typing_extensions >=x.y, <(x+1), where x.y is the first version that includes all features you need.