Skip to content

gh-91491: Complete Whats New in 3.11 for typing #92708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions Doc/whatsnew/3.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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` types can now be generic. (Contributed by
Samodya Abey in :gh:`89026`.)

* :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
type checker errors related to highly dynamic class, such as mocks.
(Contributed by Shantanu Jain in :gh:`91154`.)
Expand All @@ -739,11 +745,33 @@ 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.
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
check in the private ``typing._type_check`` function. (Contributed by
Gregory Beauregard in :gh:`90802`.)
Comment on lines +756 to +758
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we really include this? It's a private undocumented function (though David's recent bug report suggested to me otherwise).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that it's already spawned a bug report, it's likely that other users will run into this change, so I think it's important to include.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed then. Could you please add a notice strongly discouraging users from using it too? We might as well try to dissuade users though it might be in vain :).

This function is for internal use only and is **unstable** and may change across versions. Please do not use this function. Instead, we recommend implementing this with your own code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That feels like a bit much for the What's New document. We should say what changed, but I don't think we need more than that.


* :func:`typing.get_type_hints` now supports evaluating strings as forward
references in :ref:`PEP 585 generic aliases <types-genericalias>`.
(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`.)


tkinter
Expand Down Expand Up @@ -1232,6 +1260,10 @@ Deprecated
wherever possible.
(Contributed by Alex Waygood in :gh:`92332`.)

* The keyword argument syntax for constructing :data:`~typing.TypedDict` types
is now deprecated. Support will be removed in Python 3.13. (Contributed by
Jingchen Ye in :gh:`90224`.)


Pending Removal in Python 3.12
==============================
Expand Down