bpo-31082: Use "iterable" in the docstring for functools.reduce() (GH-20796)

This commit is contained in:
Zackery Spytz 2020-06-28 00:40:54 -06:00 committed by GitHub
parent 8ab77c6f9f
commit cd3c2bdd5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 14 deletions

View File

@ -236,14 +236,14 @@ _initial_missing = object()
def reduce(function, sequence, initial=_initial_missing): def reduce(function, sequence, initial=_initial_missing):
""" """
reduce(function, sequence[, initial]) -> value reduce(function, iterable[, initial]) -> value
Apply a function of two arguments cumulatively to the items of a sequence, Apply a function of two arguments cumulatively to the items of a sequence
from left to right, so as to reduce the sequence to a single value. or iterable, from left to right, so as to reduce the iterable to a single
For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates
((((1+2)+3)+4)+5). If initial is present, it is placed before the items ((((1+2)+3)+4)+5). If initial is present, it is placed before the items
of the sequence in the calculation, and serves as a default when the of the iterable in the calculation, and serves as a default when the
sequence is empty. iterable is empty.
""" """
it = iter(sequence) it = iter(sequence)
@ -252,7 +252,8 @@ def reduce(function, sequence, initial=_initial_missing):
try: try:
value = next(it) value = next(it)
except StopIteration: except StopIteration:
raise TypeError("reduce() of empty sequence with no initial value") from None raise TypeError(
"reduce() of empty iterable with no initial value") from None
else: else:
value = initial value = initial

View File

@ -0,0 +1 @@
Use the term "iterable" in the docstring for :func:`functools.reduce`.

View File

@ -679,7 +679,7 @@ functools_reduce(PyObject *self, PyObject *args)
if (result == NULL) if (result == NULL)
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"reduce() of empty sequence with no initial value"); "reduce() of empty iterable with no initial value");
Py_DECREF(it); Py_DECREF(it);
return result; return result;
@ -692,14 +692,14 @@ Fail:
} }
PyDoc_STRVAR(functools_reduce_doc, PyDoc_STRVAR(functools_reduce_doc,
"reduce(function, sequence[, initial]) -> value\n\ "reduce(function, iterable[, initial]) -> value\n\
\n\ \n\
Apply a function of two arguments cumulatively to the items of a sequence,\n\ Apply a function of two arguments cumulatively to the items of a sequence\n\
from left to right, so as to reduce the sequence to a single value.\n\ or iterable, from left to right, so as to reduce the iterable to a single\n\
For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates\n\ value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates\n\
((((1+2)+3)+4)+5). If initial is present, it is placed before the items\n\ ((((1+2)+3)+4)+5). If initial is present, it is placed before the items\n\
of the sequence in the calculation, and serves as a default when the\n\ of the iterable in the calculation, and serves as a default when the\n\
sequence is empty."); iterable is empty.");
/* lru_cache object **********************************************************/ /* lru_cache object **********************************************************/