mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
gh-103629: Update typing.Unpack docs in compliance with PEP 692 (#103894)
This commit is contained in:
parent
a3a5b4bb23
commit
dc3f97549a
3 changed files with 58 additions and 2 deletions
|
|
@ -66,6 +66,10 @@ Summary -- Release highlights
|
|||
|
||||
.. PEP-sized items next.
|
||||
|
||||
New typing features:
|
||||
|
||||
* :ref:`whatsnew312-pep692`
|
||||
|
||||
Important deprecations, removals or restrictions:
|
||||
|
||||
* :pep:`623`, Remove wstr from Unicode
|
||||
|
|
@ -145,6 +149,36 @@ New Features
|
|||
In Python 3.14, the default will switch to ``'data'``.
|
||||
(Contributed by Petr Viktorin in :pep:`706`.)
|
||||
|
||||
New Features Related to Type Hints
|
||||
==================================
|
||||
|
||||
This section covers major changes affecting :pep:`484` type hints and
|
||||
the :mod:`typing` module.
|
||||
|
||||
.. _whatsnew312-pep692:
|
||||
|
||||
PEP 692: Using ``TypedDict`` for more precise ``**kwargs`` typing
|
||||
-----------------------------------------------------------------
|
||||
|
||||
Typing ``**kwargs`` in a function signature as introduced by :pep:`484` allowed
|
||||
for valid annotations only in cases where all of the ``**kwargs`` were of the
|
||||
same type.
|
||||
|
||||
This PEP specifies a more precise way of typing ``**kwargs`` by relying on
|
||||
typed dictionaries::
|
||||
|
||||
from typing import TypedDict, Unpack
|
||||
|
||||
class Movie(TypedDict):
|
||||
name: str
|
||||
year: int
|
||||
|
||||
def foo(**kwargs: Unpack[Movie]): ...
|
||||
|
||||
See :pep:`692` for more details.
|
||||
|
||||
(PEP written by Franek Magiera)
|
||||
|
||||
|
||||
Other Language Changes
|
||||
======================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue