]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-42198: Document __new__ for types.GenericAlias (GH-23039)
authorkj <28750310+Fidget-Spinner@users.noreply.github.com>
Sat, 31 Oct 2020 06:02:38 +0000 (14:02 +0800)
committerGitHub <noreply@github.com>
Sat, 31 Oct 2020 06:02:38 +0000 (23:02 -0700)
Doc/library/stdtypes.rst
Doc/library/types.rst

index 3fd94ea1bd310bfafb2e3da557394a6e4b151e61..09477e63786c5927c0b1fd5f82abb3edc01f146c 100644 (file)
@@ -4793,7 +4793,8 @@ The ``GenericAlias`` object acts as a proxy for :term:`generic types
 of a generic which provides the types for container elements.
 
 The user-exposed type for the ``GenericAlias`` object can be accessed from
-:data:`types.GenericAlias` and used for :func:`isinstance` checks.
+:class:`types.GenericAlias` and used for :func:`isinstance` checks.  It can
+also be used to create ``GenericAlias`` objects directly.
 
 .. describe:: T[X, Y, ...]
 
index 00720559d0a4a846608eb71ff45fcf9b3dd64a6a..ad40a9fbf327398c10ace11b3fa2daf1a104d6d6 100644 (file)
@@ -262,11 +262,22 @@ Standard names are defined for the following types:
 
    .. versionadded:: 3.10
 
-.. data:: GenericAlias
+.. class:: GenericAlias(t_origin, t_args)
 
    The type of :ref:`parameterized generics <types-genericalias>` such as
    ``list[int]``.
 
+   ``t_origin`` should be a non-parameterized generic class, such as ``list``,
+   ``tuple`` or ``dict``.  ``t_args`` should be a :class:`tuple` (possibly of
+   length 1) of types which parameterize ``t_origin``::
+
+      >>> from types import GenericAlias
+
+      >>> list[int] == GenericAlias(list, (int,))
+      True
+      >>> dict[str, int] == GenericAlias(dict, (str, int))
+      True
+
    .. versionadded:: 3.9
 
 .. data:: Union