Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d75f6f7

Browse files
bpo-42675: Document collections.abc.Callable changes (GH-23839)
1 parent 17ef431 commit d75f6f7

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

Doc/library/types.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ Standard names are defined for the following types:
280280

281281
.. versionadded:: 3.9
282282

283+
.. versionchanged:: 3.9.2
284+
This type can now be subclassed.
285+
286+
283287
.. data:: Union
284288

285289
The type of :ref:`union type expressions<types-union>`.

Doc/whatsnew/3.10.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,21 @@ codecs
179179
Add a :func:`codecs.unregister` function to unregister a codec search function.
180180
(Contributed by Hai Shi in :issue:`41842`.)
181181

182+
collections.abc
183+
---------------
184+
185+
The ``__args__`` of the :ref:`parameterized generic <types-genericalias>` for
186+
:class:`collections.abc.Callable` are now consistent with :data:`typing.Callable`.
187+
:class:`collections.abc.Callable` generic now flattens type parameters, similar
188+
to what :data:`typing.Callable` currently does. This means that
189+
``collections.abc.Callable[[int, str], str]`` will have ``__args__`` of
190+
``(int, str, str)``; previously this was ``([int, str], str)``. To allow this
191+
change, :class:`types.GenericAlias` can now be subclassed, and a subclass will
192+
be returned when subscripting the :class:`collections.abc.Callable` type. Note
193+
that a :exc:`TypeError` may be raised for invalid forms of parameterizing
194+
:class:`collections.abc.Callable` which may have passed silently in Python 3.9.
195+
(Contributed by Ken Jin in :issue:`42195`.)
196+
182197
contextlib
183198
----------
184199

@@ -507,6 +522,15 @@ Changes in the Python API
507522
ignored.
508523
(Contributed by Victor Stinner in :issue:`42639`.)
509524

525+
* :class:`collections.abc.Callable` generic now flattens type parameters, similar
526+
to what :data:`typing.Callable` currently does. This means that
527+
``collections.abc.Callable[[int, str], str]`` will have ``__args__`` of
528+
``(int, str, str)``; previously this was ``([int, str], str)``. Code which
529+
accesses the arguments via :func:`typing.get_args` or ``__args__`` need to account
530+
for this change. Furthermore, :exc:`TypeError` may be raised for invalid forms
531+
of parameterizing :class:`collections.abc.Callable` which may have passed
532+
silently in Python 3.9.
533+
(Contributed by Ken Jin in :issue:`42195`.)
510534

511535
CPython bytecode changes
512536
========================

0 commit comments

Comments
 (0)