Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Doc/c-api/typehints.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ two types exist -- :ref:`GenericAlias <types-genericalias>` and
static PyMethodDef my_obj_methods[] = {
// Other methods.
...
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, "See PEP 585"}
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, "my_obj is generic over its contained type"}
...
}

Expand Down
2 changes: 2 additions & 0 deletions Doc/library/array.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ The module defines the following type:
:exc:`TypeError` is raised. Array objects also implement the buffer interface,
and may be used wherever :term:`bytes-like objects <bytes-like object>` are supported.

Arrays are :ref:`generic <generics>` over the type of their contents.

.. audit-event:: array.__new__ typecode,initializer array.array


Expand Down
2 changes: 2 additions & 0 deletions Doc/library/asyncio-future.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ Future Object
implementations can inject their own optimized implementations
of a Future object.

Futures are :ref:`generic <generics>` over the type of their return value.

.. versionchanged:: 3.7
Added support for the :mod:`contextvars` module.

Expand Down
3 changes: 3 additions & 0 deletions Doc/library/asyncio-task.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,9 @@ Task object
blocks. If the coroutine returns or raises without blocking, the task
will be finished eagerly and will skip scheduling to the event loop.

Tasks are :ref:`generic <generics>` over the return type of their contained
coroutine.

.. versionchanged:: 3.7
Added support for the :mod:`contextvars` module.

Expand Down
7 changes: 7 additions & 0 deletions Doc/library/collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,9 @@ or subtracting from an empty counter.
where only the most recent activity is of interest.


deques are :ref:`generic <generics>` over the type of their contents.


Deque objects support the following methods:

.. method:: append(item, /)
Expand Down Expand Up @@ -740,6 +743,10 @@ stack manipulations such as ``dup``, ``drop``, ``swap``, ``over``, ``pick``,
arguments.


defaultdicts are :ref:`generic <generics>` over two types, for the types of
keys and values, respectively.


:class:`defaultdict` objects support the following method in addition to the
standard :class:`dict` operations:

Expand Down
5 changes: 5 additions & 0 deletions Doc/library/contextvars.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Context Variables
references to context variables which prevents context variables
from being properly garbage collected.

Context Variables are :ref:`generic <generics>` over the type of their value.

.. attribute:: ContextVar.name

The name of the variable. This is a read-only property.
Expand Down Expand Up @@ -130,6 +132,9 @@ Context Variables
Tokens support the :ref:`context manager protocol <context-managers>`
to automatically reset context variables. See :meth:`ContextVar.set`.

Tokens are :ref:`generic <generics>` over the same type as the
:class:`ContextVar` which created them.

.. versionadded:: 3.14

Added support for usage as a context manager.
Expand Down
1 change: 1 addition & 0 deletions Doc/library/ctypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3171,6 +3171,7 @@ Arrays and pointers
subscript and slice accesses; for slice reads, the resulting object is
*not* itself an :class:`Array`.

Arrays are :ref:`generic <generics>` over the type of their values.

.. attribute:: _length_

Expand Down
3 changes: 3 additions & 0 deletions Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2994,6 +2994,9 @@ features:
To be directly usable as a :term:`path-like object`, ``os.DirEntry``
implements the :class:`PathLike` interface.

DirEntry objects are :ref:`generic <generics>` over the type of the path (str
or bytes).

Attributes and methods on a ``os.DirEntry`` instance are as follows:

.. attribute:: name
Expand Down
2 changes: 2 additions & 0 deletions Doc/library/queue.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ The :mod:`!queue` module defines the following classes and exceptions:
Constructor for an unbounded :abbr:`FIFO (first-in, first-out)` queue.
Simple queues lack advanced functionality such as task tracking.

Simple queues are :ref:`generic <generics>` over the type of their contents.

.. versionadded:: 3.7


Expand Down
5 changes: 5 additions & 0 deletions Doc/library/re.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,8 @@ Regular expression objects

Compiled regular expression object returned by :func:`re.compile`.

Patterns are :ref:`generic <generics>` over the type of string they handle (str or bytes).

.. versionchanged:: 3.9
:py:class:`re.Pattern` supports ``[]`` to indicate a Unicode (str) or bytes pattern.
See :ref:`types-genericalias`.
Expand Down Expand Up @@ -1419,6 +1421,9 @@ when there is no match, you can test whether there was a match with a simple

Match object returned by successful ``match``\ es and ``search``\ es.

Matches are :ref:`generic <generics>` over the type of string which was
matched (str or bytes).

.. versionchanged:: 3.9
:py:class:`re.Match` supports ``[]`` to indicate a Unicode (str) or bytes match.
See :ref:`types-genericalias`.
Expand Down
2 changes: 2 additions & 0 deletions Doc/library/string.templatelib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ Types
...
3.0 | 1. + 2. | None | .2f

Interpolations are :ref:`generic <generics>` over the types of their values.

.. rubric:: Attributes

.. attribute:: value
Expand Down
3 changes: 3 additions & 0 deletions Doc/library/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ Standard names are defined for the following types:
entries, which means that when the mapping changes, the view reflects these
changes.

MappingProxyTypes are :ref:`generic <generics>` over two types, for the keys
and values, respectively.

.. versionadded:: 3.3

.. versionchanged:: 3.9
Expand Down
3 changes: 3 additions & 0 deletions Doc/library/weakref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ See :ref:`__slots__ documentation <slots>` for details.

This is a subclassable type rather than a factory function.

Weak references are :ref:`generic <generics>` over the type of the object they
reference.

.. attribute:: __callback__

This read-only attribute returns the callback currently associated to the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Generic builtin and standard library types now document the meaning of their
type parameters.
6 changes: 4 additions & 2 deletions Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1741,7 +1741,8 @@ static PyMethodDef FutureType_methods[] = {
_ASYNCIO_FUTURE_DONE_METHODDEF
_ASYNCIO_FUTURE_GET_LOOP_METHODDEF
_ASYNCIO_FUTURE__MAKE_CANCELLED_ERROR_METHODDEF
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
PyDoc_STR("Futures are generic over their return type")},
{NULL, NULL} /* Sentinel */
};

Expand Down Expand Up @@ -2926,7 +2927,8 @@ static PyMethodDef TaskType_methods[] = {
_ASYNCIO_TASK_SET_NAME_METHODDEF
_ASYNCIO_TASK_GET_CORO_METHODDEF
_ASYNCIO_TASK_GET_CONTEXT_METHODDEF
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
PyDoc_STR("Tasks are generic over the return type of their contained coroutine")},
{NULL, NULL} /* Sentinel */
};

Expand Down
4 changes: 2 additions & 2 deletions Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1854,7 +1854,7 @@ static PyMethodDef deque_methods[] = {
DEQUE_ROTATE_METHODDEF
DEQUE___SIZEOF___METHODDEF
{"__class_getitem__", Py_GenericAlias,
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
METH_O|METH_CLASS, PyDoc_STR("deques are generic over the type of their contents")},
{NULL, NULL} /* sentinel */
};

Expand Down Expand Up @@ -2340,7 +2340,7 @@ static PyMethodDef defdict_methods[] = {
{"__reduce__", defdict_reduce, METH_NOARGS,
reduce_doc},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
PyDoc_STR("See PEP 585")},
PyDoc_STR("defaultdicts are generic over two types, for the types of keys and values, respectively")},
{NULL}
};

Expand Down
2 changes: 1 addition & 1 deletion Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -5305,7 +5305,7 @@ Array_length(PyObject *myself)

static PyMethodDef Array_methods[] = {
{"__class_getitem__", Py_GenericAlias,
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
METH_O|METH_CLASS, PyDoc_STR("Arrays are generic over the type of their contents")},
{ NULL, NULL }
};

Expand Down
3 changes: 2 additions & 1 deletion Modules/_functoolsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,8 @@ static PyMethodDef partial_methods[] = {
{"__reduce__", partial_reduce, METH_NOARGS},
{"__setstate__", partial_setstate, METH_O},
{"__class_getitem__", Py_GenericAlias,
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
METH_O|METH_CLASS,
PyDoc_STR("partial is generic over the wrapped function's return type")},
{NULL, NULL} /* sentinel */
};

Expand Down
2 changes: 1 addition & 1 deletion Modules/_queuemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ static PyMethodDef simplequeue_methods[] = {
_QUEUE_SIMPLEQUEUE_QSIZE_METHODDEF
_QUEUE_SIMPLEQUEUE___SIZEOF___METHODDEF
{"__class_getitem__", Py_GenericAlias,
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
METH_O|METH_CLASS, PyDoc_STR("SimpleQueues are generic over the type of their contents")},
{NULL, NULL} /* sentinel */
};

Expand Down
4 changes: 2 additions & 2 deletions Modules/_sre/sre.c
Original file line number Diff line number Diff line change
Expand Up @@ -3179,7 +3179,7 @@ static PyMethodDef pattern_methods[] = {
_SRE_SRE_PATTERN___DEEPCOPY___METHODDEF
_SRE_SRE_PATTERN__FAIL_AFTER_METHODDEF
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
PyDoc_STR("See PEP 585")},
PyDoc_STR("Patterns are generic over the type of string they handle (str or bytes)")},
{NULL, NULL}
};

Expand Down Expand Up @@ -3235,7 +3235,7 @@ static PyMethodDef match_methods[] = {
_SRE_SRE_MATCH___COPY___METHODDEF
_SRE_SRE_MATCH___DEEPCOPY___METHODDEF
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
PyDoc_STR("See PEP 585")},
PyDoc_STR("Matches are generic over the type of string which was matched (str or bytes)")},
{NULL, NULL}
};

Expand Down
3 changes: 2 additions & 1 deletion Modules/arraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2679,7 +2679,8 @@ static PyMethodDef array_methods[] = {
ARRAY_ARRAY_TOBYTES_METHODDEF
ARRAY_ARRAY_TOUNICODE_METHODDEF
ARRAY_ARRAY___SIZEOF___METHODDEF
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
PyDoc_STR("Arrays are generic over the type of their contents")},
{NULL, NULL} /* sentinel */
};

Expand Down
6 changes: 5 additions & 1 deletion Modules/itertoolsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1950,10 +1950,14 @@ Return a chain object whose .__next__() method returns elements from the\n\
first iterable until it is exhausted, then elements from the next\n\
iterable, until all of the iterables are exhausted.");

PyDoc_STRVAR(chain_class_getitem_doc,
"chain is generic over the type of its contents.\n\
This is the union of the types of the input iterable contents.");

static PyMethodDef chain_methods[] = {
ITERTOOLS_CHAIN_FROM_ITERABLE_METHODDEF
{"__class_getitem__", Py_GenericAlias,
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
METH_O|METH_CLASS, chain_class_getitem_doc},
{NULL, NULL} /* sentinel */
};

Expand Down
2 changes: 1 addition & 1 deletion Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -16538,7 +16538,7 @@ static PyMethodDef DirEntry_methods[] = {
OS_DIRENTRY_INODE_METHODDEF
OS_DIRENTRY___FSPATH___METHODDEF
{"__class_getitem__", Py_GenericAlias,
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
METH_O|METH_CLASS, PyDoc_STR("DirEntry is generic over the type of the path (str or bytes)")},
{NULL}
};

Expand Down
2 changes: 1 addition & 1 deletion Objects/descrobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ static PyMethodDef mappingproxy_methods[] = {
{"copy", mappingproxy_copy, METH_NOARGS,
PyDoc_STR("D.copy() -> a shallow copy of D")},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
PyDoc_STR("See PEP 585")},
PyDoc_STR("mappingproxy objects are generic over two types, for their keys and values, respectively")},
{"__reversed__", mappingproxy_reversed, METH_NOARGS,
PyDoc_STR("D.__reversed__() -> reverse iterator")},
{0}
Expand Down
6 changes: 4 additions & 2 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5129,7 +5129,8 @@ static PyMethodDef mapp_methods[] = {
DICT_CLEAR_METHODDEF
DICT_COPY_METHODDEF
DICT___REVERSED___METHODDEF
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
PyDoc_STR("dicts are generic over two types, for their keys and values, respectively")},
{NULL, NULL} /* sentinel */
};

Expand Down Expand Up @@ -8197,7 +8198,8 @@ static PyMethodDef frozendict_methods[] = {
DICT_FROMKEYS_METHODDEF
FROZENDICT_COPY_METHODDEF
DICT___REVERSED___METHODDEF
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
PyDoc_STR("frozendicts are generic over two types, for their keys and values, respectively")},
{"__getnewargs__", frozendict_getnewargs, METH_NOARGS},
{NULL, NULL} /* sentinel */
};
Expand Down
2 changes: 1 addition & 1 deletion Objects/enumobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
static PyMethodDef enum_methods[] = {
{"__reduce__", enum_reduce, METH_NOARGS, reduce_doc},
{"__class_getitem__", Py_GenericAlias,
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
METH_O|METH_CLASS, PyDoc_STR("enumerations are generic over the type of their values")},
{NULL, NULL} /* sentinel */
};

Expand Down
3 changes: 2 additions & 1 deletion Objects/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,8 @@ static PyMemberDef BaseExceptionGroup_members[] = {

static PyMethodDef BaseExceptionGroup_methods[] = {
{"__class_getitem__", Py_GenericAlias,
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
METH_O|METH_CLASS,
PyDoc_STR("Exception groups are generic over the type of their inner exceptions")},
BASEEXCEPTIONGROUP_DERIVE_METHODDEF
BASEEXCEPTIONGROUP_SPLIT_METHODDEF
BASEEXCEPTIONGROUP_SUBGROUP_METHODDEF
Expand Down
8 changes: 5 additions & 3 deletions Objects/genobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,8 @@ static PyMethodDef gen_methods[] = {
{"throw", _PyCFunction_CAST(gen_throw), METH_FASTCALL, throw_doc},
{"close", gen_close, METH_NOARGS, close_doc},
{"__sizeof__", gen_sizeof, METH_NOARGS, sizeof__doc__},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
PyDoc_STR("generators are generic over the types of their yield, send, and return values")},
{NULL, NULL} /* Sentinel */
};

Expand Down Expand Up @@ -1374,7 +1375,8 @@ static PyMethodDef coro_methods[] = {
{"throw",_PyCFunction_CAST(gen_throw), METH_FASTCALL, coro_throw_doc},
{"close", gen_close, METH_NOARGS, coro_close_doc},
{"__sizeof__", gen_sizeof, METH_NOARGS, sizeof__doc__},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
PyDoc_STR("coroutines are generic over the types of their yield, send, and return values")},
{NULL, NULL} /* Sentinel */
};

Expand Down Expand Up @@ -1820,7 +1822,7 @@ static PyMethodDef async_gen_methods[] = {
{"aclose", async_gen_aclose, METH_NOARGS, async_aclose_doc},
{"__sizeof__", gen_sizeof, METH_NOARGS, sizeof__doc__},
{"__class_getitem__", Py_GenericAlias,
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
METH_O|METH_CLASS, PyDoc_STR("async generators are generic over the types of their yield and send values")},
{NULL, NULL} /* Sentinel */
};

Expand Down
2 changes: 1 addition & 1 deletion Objects/interpolationobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static PyMethodDef interpolation_methods[] = {
{"__reduce__", interpolation_reduce, METH_NOARGS,
PyDoc_STR("__reduce__() -> (cls, state)")},
{"__class_getitem__", Py_GenericAlias,
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
METH_O|METH_CLASS, PyDoc_STR("Interpolations are generic over the types of their values")},
{NULL, NULL},
};

Expand Down
3 changes: 2 additions & 1 deletion Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3611,7 +3611,8 @@ static PyMethodDef list_methods[] = {
LIST_COUNT_METHODDEF
LIST_REVERSE_METHODDEF
LIST_SORT_METHODDEF
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
PyDoc_STR("lists are generic over the type of their contents")},
{NULL, NULL} /* sentinel */
};

Expand Down
3 changes: 2 additions & 1 deletion Objects/memoryobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3579,7 +3579,8 @@ static PyMethodDef memory_methods[] = {
MEMORYVIEW_INDEX_METHODDEF
{"__enter__", memory_enter, METH_NOARGS, NULL},
{"__exit__", memory_exit, METH_VARARGS, memory_exit_doc},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
PyDoc_STR("memoryviews are generic over the type of their contents, as retrieved by indexing")},
{NULL, NULL}
};

Expand Down
6 changes: 4 additions & 2 deletions Objects/setobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2800,7 +2800,8 @@ static PyMethodDef set_methods[] = {
SET_SYMMETRIC_DIFFERENCE_UPDATE_METHODDEF
SET_UNION_METHODDEF
SET_UPDATE_METHODDEF
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
PyDoc_STR("sets are generic over the type of their contents")},
{NULL, NULL} /* sentinel */
};

Expand Down Expand Up @@ -2904,7 +2905,8 @@ static PyMethodDef frozenset_methods[] = {
SET___SIZEOF___METHODDEF
SET_SYMMETRIC_DIFFERENCE_METHODDEF
SET_UNION_METHODDEF
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
PyDoc_STR("frozensets are generic over the type of their contents")},
{NULL, NULL} /* sentinel */
};

Expand Down
Loading
Loading