- `typing_extensions` is now documented at
https://typing-extensions.readthedocs.io/en/latest/. Patch by Jelle Zijlstra.
- Add `typing_extensions.Buffer`, a marker class for buffer types, as proposed
by PEP 688. Equivalent to `collections.abc.Buffer` in Python 3.12. Patch by
Jelle Zijlstra.
- Backport two CPython PRs fixing various issues with `typing.Literal`:
https://github.com/python/cpython/pull/23294 and
https://github.com/python/cpython/pull/23383. Both CPython PRs were
originally by Yurii Karabas, and both were backported to Python >=3.9.1, but
no earlier. Patch by Alex Waygood.
A side effect of one of the changes is that equality comparisons of `Literal`
objects will now raise a `TypeError` if one of the `Literal` objects being
compared has a mutable parameter. (Using mutable parameters with `Literal` is
not supported by PEP 586 or by any major static type checkers.)
- `Literal` is now reimplemented on all Python versions <= 3.10.0. The
`typing_extensions` version does not suffer from the bug that was fixed in
https://github.com/python/cpython/pull/29334. (The CPython bugfix was
backported to CPython 3.10.1 and 3.9.8, but no earlier.)
- Backport [CPython PR 26067](https://github.com/python/cpython/pull/26067)
(originally by Yurii Karabas), ensuring that `isinstance()` calls on
protocols raise `TypeError` when the protocol is not decorated with
`runtime_checkable`. Patch by Alex Waygood.
- Backport several significant performance improvements to runtime-checkable
protocols that have been made in Python 3.12 (see
https://github.com/python/cpython/issues/74690 for details). Patch by Alex
Waygood.
A side effect of one of the performance improvements is that the members of
a runtime-checkable protocol are now considered “frozen” at runtime as soon
as the class has been created. Monkey-patching attributes onto a
runtime-checkable protocol will still work, but will have no impact on
`isinstance()` checks comparing objects to the protocol. See
["What's New in Python 3.12"](https://docs.python.org/3.12/whatsnew/3.12.html#typing)
for more details.
- `isinstance()` checks against runtime-checkable protocols now use
`inspect.getattr_static()` rather than `hasattr()` to lookup whether
attributes exist (backporting https://github.com/python/cpython/pull/103034).
This means that descriptors and `__getattr__` methods are no longer
unexpectedly evaluated during `isinstance()` checks against runtime-checkable
protocols. However, it may also mean that some objects which used to be
considered instances of a runtime-checkable protocol on older versions of
`typing_extensions` may no longer be considered instances of that protocol
using the new release, and vice versa. Most users are unlikely to be affected
by this change. Patch by Alex Waygood.
- Backport the ability to define `__init__` methods on Protocol classes, a
change made in Python 3.11 (originally implemented in
https://github.com/python/cpython/pull/31628 by Adrian Garcia Badaracco).
Patch by Alex Waygood.
- Speedup `isinstance(3, typing_extensions.SupportsIndex)` by >10x on Python
<3.12. Patch by Alex Waygood.
- Add `typing_extensions` versions of `SupportsInt`, `SupportsFloat`,
`SupportsComplex`, `SupportsBytes`, `SupportsAbs` and `SupportsRound`. These
have the same semantics as the versions from the `typing` module, but
`isinstance()` checks against the `typing_extensions` versions are >10x faster
at runtime on Python <3.12. Patch by Alex Waygood.
- Add `__orig_bases__` to non-generic TypedDicts, call-based TypedDicts, and
call-based NamedTuples. Other TypedDicts and NamedTuples already had the attribute.
Patch by Adrian Garcia Badaracco.
- Add `typing_extensions.get_original_bases`, a backport of
[`types.get_original_bases`](https://docs.python.org/3.12/library/types.html#types.get_original_bases),
introduced in Python 3.12 (CPython PR
https://github.com/python/cpython/pull/101827, originally by James
Hilton-Balfe). Patch by Alex Waygood.
This function should always produce correct results when called on classes
constructed using features from `typing_extensions`. However, it may
produce incorrect results when called on some `NamedTuple` or `TypedDict`
classes that use `typing.{NamedTuple,TypedDict}` on Python <=3.11.
- Constructing a call-based `TypedDict` using keyword arguments for the fields
now causes a `DeprecationWarning` to be emitted. This matches the behaviour
of `typing.TypedDict` on 3.11 and 3.12.
- Backport the implementation of `NewType` from 3.10 (where it is implemented
as a class rather than a function). This allows user-defined `NewType`s to be
pickled. Patch by Alex Waygood.
- Fix tests and import on Python 3.12, where `typing.TypeVar` can no longer be
subclassed. Patch by Jelle Zijlstra.
- Add `typing_extensions.TypeAliasType`, a backport of `typing.TypeAliasType`
from PEP 695. Patch by Jelle Zijlstra.
- Backport changes to the repr of `typing.Unpack` that were made in order to
implement [PEP 692](https://peps.python.org/pep-0692/) (backport of
https://github.com/python/cpython/pull/104048). Patch by Alex Waygood.