summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorSamodya Abey <379594+sransara@users.noreply.github.com>2022-05-03 13:21:42 (GMT)
committerGitHub <noreply@github.com>2022-05-03 13:21:42 (GMT)
commitf6f36cc26978e3036a6c5c068fca5b8135f27ef3 (patch)
tree9eb2066906acec8e06ee0d355dcb0c71908bd2c1 /Doc/library
parent6c7249f2655749a06b4674a17537f844bd54d217 (diff)
downloadcpython-f6f36cc26978e3036a6c5c068fca5b8135f27ef3.zip
cpython-f6f36cc26978e3036a6c5c068fca5b8135f27ef3.tar.gz
cpython-f6f36cc26978e3036a6c5c068fca5b8135f27ef3.tar.bz2
bpo-44863: Allow generic typing.TypedDict (#27663)
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/typing.rst11
1 files changed, 10 insertions, 1 deletions
diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst
index 05ac057..c9fc944 100644
--- a/Doc/library/typing.rst
+++ b/Doc/library/typing.rst
@@ -1738,7 +1738,7 @@ These are not used in annotations. They are building blocks for declaring types.
z: int
A ``TypedDict`` cannot inherit from a non-TypedDict class,
- notably including :class:`Generic`. For example::
+ except for :class:`Generic`. For example::
class X(TypedDict):
x: int
@@ -1755,6 +1755,12 @@ These are not used in annotations. They are building blocks for declaring types.
T = TypeVar('T')
class XT(X, Generic[T]): pass # raises TypeError
+ A ``TypedDict`` can be generic::
+
+ class Group(TypedDict, Generic[T]):
+ key: T
+ group: list[T]
+
A ``TypedDict`` can be introspected via annotations dicts
(see :ref:`annotations-howto` for more information on annotations best practices),
:attr:`__total__`, :attr:`__required_keys__`, and :attr:`__optional_keys__`.
@@ -1802,6 +1808,9 @@ These are not used in annotations. They are building blocks for declaring types.
.. versionadded:: 3.8
+ .. versionchanged:: 3.11
+ Added support for generic ``TypedDict``\ s.
+
Generic concrete collections
----------------------------