This is a feature release. Major changes include:
- All non-deprecated names from
typing
are now re-exported bytyping_extensions
for convenience - Add
typing_extensions.get_protocol_members
andtyping_extensions.is_protocol
- Declare support for Python 3.12
- This will be the last feature release to support Python 3.7, which recently reached its end-of-life
Full changelog of versions 4.7.0 and 4.7.0rc1:
Release 4.7.0 (June 28, 2023)
- This is expected to be the last feature release supporting Python 3.7,
which reaches its end of life on June 27, 2023. Version 4.8.0 will support
only Python 3.8.0 and up. - Fix bug where a
typing_extensions.Protocol
class that had one or more
non-callable members would raiseTypeError
whenissubclass()
was called against it, even if it defined a custom__subclasshook__
method. The correct behaviour -- which has now been restored -- is not to
raiseTypeError
in these situations if a custom__subclasshook__
method
is defined. Patch by Alex Waygood (backporting
python/cpython#105976).
Release 4.7.0rc1 (June 21, 2023)
- Add
typing_extensions.get_protocol_members
and
typing_extensions.is_protocol
(backport of CPython PR #104878).
Patch by Jelle Zijlstra. typing_extensions
now re-exports all names in the standard library's
typing
module, except the deprecatedByteString
. Patch by Jelle
Zijlstra.- Due to changes in the implementation of
typing_extensions.Protocol
,
typing.runtime_checkable
can now be used ontyping_extensions.Protocol
(previously, users had to usetyping_extensions.runtime_checkable
if they
were usingtyping_extensions.Protocol
). - Align the implementation of
TypedDict
with the implementation in the
standard library on Python 3.9 and higher.
typing_extensions.TypedDict
is now a function instead of a class. The
private functions_check_fails
,_dict_new
, and_typeddict_new
have been removed.is_typeddict
now returnsFalse
when called with
TypedDict
itself as the argument. Patch by Jelle Zijlstra. - Declare support for Python 3.12. Patch by Jelle Zijlstra.
- Fix tests on Python 3.13, which removes support for creating
TypedDict
classes through the keyword-argument syntax. Patch by
Jelle Zijlstra. - Fix a regression introduced in v4.6.3 that meant that
issubclass(object, typing_extensions.Protocol)
would erroneously raise
TypeError
. Patch by Alex Waygood (backporting the CPython PR
python/cpython#105239). - Allow
Protocol
classes to inherit fromtyping_extensions.Buffer
or
collections.abc.Buffer
. Patch by Alex Waygood (backporting
python/cpython#104827, by Jelle Zijlstra). - Allow classes to inherit from both
typing.Protocol
andtyping_extensions.Protocol
simultaneously. Since v4.6.0, this causedTypeError
to be raised due to a
metaclass conflict. Patch by Alex Waygood. - Backport several deprecations from CPython relating to unusual ways to
createTypedDict
s andNamedTuple
s. CPython PRs #105609 and #105780
by Alex Waygood;typing_extensions
backport by Jelle Zijlstra.- Creating a
NamedTuple
using the functional syntax with keyword arguments
(NT = NamedTuple("NT", a=int)
) is now deprecated. - Creating a
NamedTuple
with zero fields using the syntaxNT = NamedTuple("NT")
orNT = NamedTuple("NT", None)
is now deprecated. - Creating a
TypedDict
with zero fields using the syntaxTD = TypedDict("TD")
orTD = TypedDict("TD", None)
is now deprecated.
- Creating a
- Fix bug on Python 3.7 where a protocol
X
that had a membera
would not be
considered an implicit subclass of an unrelated protocolY
that only has a
membera
. Where the members ofX
are a superset of the members ofY
,
X
should always be considered a subclass ofY
iffY
is a
runtime-checkable protocol that only has callable members. Patch by Alex
Waygood (backporting CPython PR
python/cpython#105835).