Skip to content

Commit dbaa07d

Browse files
[3.9] bpo-42198: Document __new__ for types.GenericAlias (GH-23039) (GH-23061)
(cherry picked from commit bcbf758)
1 parent ddcd57e commit dbaa07d

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
@@ -4760,7 +4760,8 @@ The ``GenericAlias`` object acts as a proxy for :term:`generic types
47604760
of a generic which provides the types for container elements.
47614761

47624762
The user-exposed type for the ``GenericAlias`` object can be accessed from
4763-
:data:`types.GenericAlias` and used for :func:`isinstance` checks.
4763+
:class:`types.GenericAlias` and used for :func:`isinstance` checks. It can
4764+
also be used to create ``GenericAlias`` objects directly.
47644765

47654766
.. describe:: T[X, Y, ...]
47664767

Doc/library/types.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,22 @@ Standard names are defined for the following types:
242242
Defaults to ``None``. Previously the attribute was optional.
243243

244244

245-
.. data:: GenericAlias
245+
.. class:: GenericAlias(t_origin, t_args)
246246

247247
The type of :ref:`parameterized generics <types-genericalias>` such as
248248
``list[int]``.
249249

250+
``t_origin`` should be a non-parameterized generic class, such as ``list``,
251+
``tuple`` or ``dict``. ``t_args`` should be a :class:`tuple` (possibly of
252+
length 1) of types which parameterize ``t_origin``::
253+
254+
>>> from types import GenericAlias
255+
256+
>>> list[int] == GenericAlias(list, (int,))
257+
True
258+
>>> dict[str, int] == GenericAlias(dict, (str, int))
259+
True
260+
250261
.. versionadded:: 3.9
251262

252263

0 commit comments

Comments
 (0)