Skip to content

Commit bcbf758

Browse files
bpo-42198: Document __new__ for types.GenericAlias (GH-23039)
1 parent 43ca084 commit bcbf758

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Doc/library/stdtypes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4793,7 +4793,8 @@ The ``GenericAlias`` object acts as a proxy for :term:`generic types
47934793
of a generic which provides the types for container elements.
47944794

47954795
The user-exposed type for the ``GenericAlias`` object can be accessed from
4796-
:data:`types.GenericAlias` and used for :func:`isinstance` checks.
4796+
:class:`types.GenericAlias` and used for :func:`isinstance` checks. It can
4797+
also be used to create ``GenericAlias`` objects directly.
47974798

47984799
.. describe:: T[X, Y, ...]
47994800

Doc/library/types.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,22 @@ Standard names are defined for the following types:
262262

263263
.. versionadded:: 3.10
264264

265-
.. data:: GenericAlias
265+
.. class:: GenericAlias(t_origin, t_args)
266266

267267
The type of :ref:`parameterized generics <types-genericalias>` such as
268268
``list[int]``.
269269

270+
``t_origin`` should be a non-parameterized generic class, such as ``list``,
271+
``tuple`` or ``dict``. ``t_args`` should be a :class:`tuple` (possibly of
272+
length 1) of types which parameterize ``t_origin``::
273+
274+
>>> from types import GenericAlias
275+
276+
>>> list[int] == GenericAlias(list, (int,))
277+
True
278+
>>> dict[str, int] == GenericAlias(dict, (str, int))
279+
True
280+
270281
.. versionadded:: 3.9
271282

272283
.. data:: Union

0 commit comments

Comments
 (0)