Skip to content

Commit cd3c2bd

Browse files
authoredJun 28, 2020
bpo-31082: Use "iterable" in the docstring for functools.reduce() (pythonGH-20796)
1 parent 8ab77c6 commit cd3c2bd

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed
 

‎Lib/functools.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,14 @@ def __ge__(self, other):
236236

237237
def reduce(function, sequence, initial=_initial_missing):
238238
"""
239-
reduce(function, sequence[, initial]) -> value
239+
reduce(function, iterable[, initial]) -> value
240240
241-
Apply a function of two arguments cumulatively to the items of a sequence,
242-
from left to right, so as to reduce the sequence to a single value.
243-
For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates
241+
Apply a function of two arguments cumulatively to the items of a sequence
242+
or iterable, from left to right, so as to reduce the iterable to a single
243+
value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates
244244
((((1+2)+3)+4)+5). If initial is present, it is placed before the items
245-
of the sequence in the calculation, and serves as a default when the
246-
sequence is empty.
245+
of the iterable in the calculation, and serves as a default when the
246+
iterable is empty.
247247
"""
248248

249249
it = iter(sequence)
@@ -252,7 +252,8 @@ def reduce(function, sequence, initial=_initial_missing):
252252
try:
253253
value = next(it)
254254
except StopIteration:
255-
raise TypeError("reduce() of empty sequence with no initial value") from None
255+
raise TypeError(
256+
"reduce() of empty iterable with no initial value") from None
256257
else:
257258
value = initial
258259

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

‎Modules/_functoolsmodule.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ functools_reduce(PyObject *self, PyObject *args)
679679

680680
if (result == NULL)
681681
PyErr_SetString(PyExc_TypeError,
682-
"reduce() of empty sequence with no initial value");
682+
"reduce() of empty iterable with no initial value");
683683

684684
Py_DECREF(it);
685685
return result;
@@ -692,14 +692,14 @@ functools_reduce(PyObject *self, PyObject *args)
692692
}
693693

694694
PyDoc_STRVAR(functools_reduce_doc,
695-
"reduce(function, sequence[, initial]) -> value\n\
695+
"reduce(function, iterable[, initial]) -> value\n\
696696
\n\
697-
Apply a function of two arguments cumulatively to the items of a sequence,\n\
698-
from left to right, so as to reduce the sequence to a single value.\n\
699-
For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates\n\
697+
Apply a function of two arguments cumulatively to the items of a sequence\n\
698+
or iterable, from left to right, so as to reduce the iterable to a single\n\
699+
value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates\n\
700700
((((1+2)+3)+4)+5). If initial is present, it is placed before the items\n\
701-
of the sequence in the calculation, and serves as a default when the\n\
702-
sequence is empty.");
701+
of the iterable in the calculation, and serves as a default when the\n\
702+
iterable is empty.");
703703

704704
/* lru_cache object **********************************************************/
705705

0 commit comments

Comments
 (0)
Failed to load comments.