[Python-checkins] [3.9] bpo-42198: Document __new__ for types.GenericAlias (GH-23039) (GH-23061)
miss-islington
webhook-mailer at python.org
Sat Oct 31 11:05:40 EDT 2020
https://github.com/python/cpython/commit/dbaa07db671c4e5842629c8be912f2b0370be794
commit: dbaa07db671c4e5842629c8be912f2b0370be794
branch: 3.9
author: kj <28750310+Fidget-Spinner at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2020-10-31T08:05:36-07:00
summary:
[3.9] bpo-42198: Document __new__ for types.GenericAlias (GH-23039) (GH-23061)
(cherry picked from commit bcbf758476c1148993ddf4b54d3f6169b973ee1c)
files:
M Doc/library/stdtypes.rst
M Doc/library/types.rst
diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst
index e19e76f8311c8..a48cfa1327791 100644
--- a/Doc/library/stdtypes.rst
+++ b/Doc/library/stdtypes.rst
@@ -4760,7 +4760,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, ...]
diff --git a/Doc/library/types.rst b/Doc/library/types.rst
index 1573e460f2f2b..5d68c6852678c 100644
--- a/Doc/library/types.rst
+++ b/Doc/library/types.rst
@@ -242,11 +242,22 @@ Standard names are defined for the following types:
Defaults to ``None``. Previously the attribute was optional.
-.. 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
More information about the Python-checkins
mailing list