Skip to content

Commit 3a51ab5

Browse files
Correct several class getitem docs
And expand the text for tuples. Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>
1 parent d797621 commit 3a51ab5

5 files changed

Lines changed: 13 additions & 10 deletions

File tree

Doc/library/string.templatelib.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ Types
7878
template.strings: ('Ah! We do have ', '.')
7979
template.values: ( 'Camembert', )
8080
81-
Templates are :ref:`generic <generics>` over the type of the values which
82-
are interpolated.
83-
8481
.. rubric:: Attributes
8582

8683
.. attribute:: strings

Objects/genobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ static PyMethodDef gen_methods[] = {
10241024
{"close", gen_close, METH_NOARGS, close_doc},
10251025
{"__sizeof__", gen_sizeof, METH_NOARGS, sizeof__doc__},
10261026
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
1027-
PyDoc_STR("generators are generic over the type of their values")},
1027+
PyDoc_STR("generators are generic over the types of their yield, send, and return values")},
10281028
{NULL, NULL} /* Sentinel */
10291029
};
10301030

@@ -1376,7 +1376,7 @@ static PyMethodDef coro_methods[] = {
13761376
{"close", gen_close, METH_NOARGS, coro_close_doc},
13771377
{"__sizeof__", gen_sizeof, METH_NOARGS, sizeof__doc__},
13781378
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
1379-
PyDoc_STR("coroutines are generic over the type of their return value")},
1379+
PyDoc_STR("coroutines are generic over the types of their yield, send, and return values")},
13801380
{NULL, NULL} /* Sentinel */
13811381
};
13821382

@@ -1822,7 +1822,7 @@ static PyMethodDef async_gen_methods[] = {
18221822
{"aclose", async_gen_aclose, METH_NOARGS, async_aclose_doc},
18231823
{"__sizeof__", gen_sizeof, METH_NOARGS, sizeof__doc__},
18241824
{"__class_getitem__", Py_GenericAlias,
1825-
METH_O|METH_CLASS, PyDoc_STR("async generators are generic over the type of their values")},
1825+
METH_O|METH_CLASS, PyDoc_STR("async generators are generic over the types of their yield and send values")},
18261826
{NULL, NULL} /* Sentinel */
18271827
};
18281828

Objects/sliceobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ static PyMethodDef slice_methods[] = {
563563
{"indices", slice_indices, METH_O, slice_indices_doc},
564564
{"__reduce__", slice_reduce, METH_NOARGS, reduce_doc},
565565
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
566-
"slices are generic over the type of their values"},
566+
"slices are generic over the types of their start, end, and step values"},
567567
{NULL, NULL}
568568
};
569569

Objects/templateobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ static PyMethodDef template_methods[] = {
376376
// note that this is not supported in typeshed, and it is not clear if the
377377
// type for this is a simple TypeVar or a TypeVarTuple
378378
// for details, see: https://github.com/python/typeshed/issues/14878
379-
PyDoc_STR("Templates are generic over the type of the values which are interpolated")},
379+
PyDoc_STR("Template supports [] for generic usage")},
380380
{NULL, NULL},
381381
};
382382

Objects/tupleobject.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -954,12 +954,18 @@ tuple___getnewargs___impl(PyTupleObject *self)
954954
return Py_BuildValue("(N)", tuple_slice(self, 0, Py_SIZE(self)));
955955
}
956956

957+
958+
PyDoc_STRVAR(tuple_class_getitem_doc,
959+
"Tuples are generic over the types of their contents.\n\
960+
The type arguments to a tuple should match the types and arity of the contents.\n\n\
961+
For example, use ``tuple[int, str]`` for a pair whose first element is an int and second element is a string.\n\n\
962+
Tuples also the form ``tuple[T, ...]`` to indicate an arbitrary length tuple of elements of type T.");
963+
957964
static PyMethodDef tuple_methods[] = {
958965
TUPLE___GETNEWARGS___METHODDEF
959966
TUPLE_INDEX_METHODDEF
960967
TUPLE_COUNT_METHODDEF
961-
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
962-
PyDoc_STR("tuples are generic over the types of their contents, with type arguments which match the types and arity of their contents")},
968+
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, tuple_class_getitem_doc},
963969
{NULL, NULL} /* sentinel */
964970
};
965971

0 commit comments

Comments
 (0)