From 0a9eb3284afe2155c3f60dc1063a591504cf36ae Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 11 May 2022 20:05:47 -0700 Subject: [PATCH 1/4] gh-91491: Complete Whats New in 3.11 for typing Fixes #91491 --- Doc/whatsnew/3.11.rst | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 6518eea4c7ba55..adb67c65b57cc6 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -726,6 +726,12 @@ For major changes, see :ref:`new-feat-related-type-hints-311`. the given type. At runtime it simply returns the received value. (Contributed by Jelle Zijlstra in :gh:`90638`.) +* :data:`typing.TypedDict` subclasses can now be generic. (Contributed by + Samodya Abey in :gh:`89026`.) + +* :class:`~typing.NamedTuple` subclasses can now be generic. + (Contributed by Serhiy Storchaka in :issue:`43923`.) + * Allow subclassing of :class:`typing.Any`. This is useful for avoiding type checker errors related to highly dynamic class, such as mocks. (Contributed by Shantanu Jain in :gh:`91154`.) @@ -739,11 +745,34 @@ For major changes, see :ref:`new-feat-related-type-hints-311`. to clear all registered overloads of a function. (Contributed by Jelle Zijlstra in :gh:`89263`.) -* :data:`typing.TypedDict` subclasses can now be generic. (Contributed by - Samodya Abey in :gh:`89026`.) +* The :meth:`__init__` method of :class:`~typing.Protocol` subclasses + is now preserved. (Contributed by Adrian Garcia Badarasco in :gh:`88970`.) -* :class:`~typing.NamedTuple` subclasses can now be generic. - (Contributed by Serhiy Storchaka in :issue:`43923`.) +* The representation of empty tuple types (``Tuple[()]``) is simplified. + (Contributed by Serhyi Storchaka in :gh:`91137`.) + +* Loosen runtime requirements for type annotations by removing the callable + check in the private ``typing._type_check`` function. (Contributed by + Gregory Beauregard in :gh:`90802`.) + +* :func:`typing.get_type_hints` now supports evaluating strings as forward + references in :ref:`PEP 585 generic aliases `. + (Contributed by Niklas Rosenstein in :gh:`85542`.) + +* :func:`typing.get_type_hints` no longer adds :data:`~typing.Optional` + to parameters with ``None`` as a default. (Contributed by Nikita Sobolev + in :gh:`90353`.) + +* :func:`typing.get_type_hints` now supports evaluating bare stringified + :data:`~typing.ClassVar` annotations. (Contributed by Gregory Beauregard + in :gh:`90711`.) + +* :func:`typing.no_type_check` no longer modifies external classes and functions. + It also now correctly marks classmethods as not to be type checked. (Contributed + by Nikita Sobolev in :gh:`90729`.) + +* The keyword argument syntax for constructing :data:`~typing.TypedDict` types + is now deprecated. (Contributed by Jingchen Ye in :gh:`90224`.) tkinter From c0d95b4d45df5ae7b7913bee1f66dfdea389b28b Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Thu, 12 May 2022 07:22:33 -0700 Subject: [PATCH 2/4] Update Doc/whatsnew/3.11.rst Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> --- Doc/whatsnew/3.11.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index adb67c65b57cc6..4ec9d9471b288f 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -749,7 +749,7 @@ For major changes, see :ref:`new-feat-related-type-hints-311`. is now preserved. (Contributed by Adrian Garcia Badarasco in :gh:`88970`.) * The representation of empty tuple types (``Tuple[()]``) is simplified. - (Contributed by Serhyi Storchaka in :gh:`91137`.) + (Contributed by Serhiy Storchaka in :gh:`91137`.) * Loosen runtime requirements for type annotations by removing the callable check in the private ``typing._type_check`` function. (Contributed by From 879808974072050ca3309960d832d6cb5a2a533a Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 17 May 2022 06:49:15 -0700 Subject: [PATCH 3/4] feedback --- Doc/whatsnew/3.11.rst | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 8eba46c940062f..7ff41c7ac5ad69 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -726,10 +726,10 @@ For major changes, see :ref:`new-feat-related-type-hints-311`. the given type. At runtime it simply returns the received value. (Contributed by Jelle Zijlstra in :gh:`90638`.) -* :data:`typing.TypedDict` subclasses can now be generic. (Contributed by +* :data:`typing.TypedDict` types can now be generic. (Contributed by Samodya Abey in :gh:`89026`.) -* :class:`~typing.NamedTuple` subclasses can now be generic. +* :class:`~typing.NamedTuple` types can now be generic. (Contributed by Serhiy Storchaka in :issue:`43923`.) * Allow subclassing of :class:`typing.Any`. This is useful for avoiding @@ -749,6 +749,8 @@ For major changes, see :ref:`new-feat-related-type-hints-311`. is now preserved. (Contributed by Adrian Garcia Badarasco in :gh:`88970`.) * The representation of empty tuple types (``Tuple[()]``) is simplified. + This affects introspection, e.g. ``get_args(Tuple[()])`` now evaluates + to ``()`` instead of ``((),)``. (Contributed by Serhiy Storchaka in :gh:`91137`.) * Loosen runtime requirements for type annotations by removing the callable @@ -771,9 +773,6 @@ For major changes, see :ref:`new-feat-related-type-hints-311`. It also now correctly marks classmethods as not to be type checked. (Contributed by Nikita Sobolev in :gh:`90729`.) -* The keyword argument syntax for constructing :data:`~typing.TypedDict` types - is now deprecated. (Contributed by Jingchen Ye in :gh:`90224`.) - tkinter ------- @@ -1261,6 +1260,9 @@ Deprecated wherever possible. (Contributed by Alex Waygood in :gh:`92332`.) +* The keyword argument syntax for constructing :data:`~typing.TypedDict` types + is now deprecated. (Contributed by Jingchen Ye in :gh:`90224`.) + Pending Removal in Python 3.12 ============================== From c242df1958aa12da47d90173a468e4e2b99cc54f Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 17 May 2022 18:04:08 -0700 Subject: [PATCH 4/4] Update Doc/whatsnew/3.11.rst Co-authored-by: Alex Waygood --- Doc/whatsnew/3.11.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 7ff41c7ac5ad69..3732c387cb5bc4 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1261,7 +1261,8 @@ Deprecated (Contributed by Alex Waygood in :gh:`92332`.) * The keyword argument syntax for constructing :data:`~typing.TypedDict` types - is now deprecated. (Contributed by Jingchen Ye in :gh:`90224`.) + is now deprecated. Support will be removed in Python 3.13. (Contributed by + Jingchen Ye in :gh:`90224`.) Pending Removal in Python 3.12