@@ -98,6 +98,9 @@ annotations. These include:
98
98
*Introducing * :data: `LiteralString `
99
99
* :pep: `681 `: Data Class Transforms
100
100
*Introducing * the :func: `@dataclass_transform<dataclass_transform> ` decorator
101
+ * :pep: `692 `: Using ``TypedDict `` for more precise ``**kwargs `` typing
102
+ *Introducing * a new way of typing ``**kwargs `` with :data: `Unpack ` and
103
+ :data: `TypedDict `
101
104
* :pep: `698 `: Adding an override decorator to typing
102
105
*Introducing * the :func: `@override<override> ` decorator
103
106
@@ -1417,8 +1420,10 @@ These are not used in annotations. They are building blocks for creating generic
1417
1420
tup: tuple[Unpack[Ts]]
1418
1421
1419
1422
In fact, ``Unpack `` can be used interchangeably with ``* `` in the context
1420
- of types. You might see ``Unpack `` being used explicitly in older versions
1421
- of Python, where ``* `` couldn't be used in certain places::
1423
+ of :class: `typing.TypeVarTuple <TypeVarTuple> ` and
1424
+ :class: `builtins.tuple <tuple> ` types. You might see ``Unpack `` being used
1425
+ explicitly in older versions of Python, where ``* `` couldn't be used in
1426
+ certain places::
1422
1427
1423
1428
# In older versions of Python, TypeVarTuple and Unpack
1424
1429
# are located in the `typing_extensions` backports package.
@@ -1428,6 +1433,21 @@ These are not used in annotations. They are building blocks for creating generic
1428
1433
tup: tuple[*Ts] # Syntax error on Python <= 3.10!
1429
1434
tup: tuple[Unpack[Ts]] # Semantically equivalent, and backwards-compatible
1430
1435
1436
+ ``Unpack `` can also be used along with :class: `typing.TypedDict ` for typing
1437
+ ``**kwargs `` in a function signature::
1438
+
1439
+ from typing import TypedDict, Unpack
1440
+
1441
+ class Movie(TypedDict):
1442
+ name: str
1443
+ year: int
1444
+
1445
+ # This function expects two keyword arguments - `name` of type `str`
1446
+ # and `year` of type `int`.
1447
+ def foo(**kwargs: Unpack[Movie]): ...
1448
+
1449
+ See :pep: `692 ` for more details on using ``Unpack `` for ``**kwargs `` typing.
1450
+
1431
1451
.. versionadded :: 3.11
1432
1452
1433
1453
.. class :: ParamSpec(name, *, bound=None, covariant=False, contravariant=False)
0 commit comments