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

Zackery Spytz webhook-mailer at python.org
Sun Jun 28 02:41:02 EDT 2020


https://github.com/python/cpython/commit/cd3c2bdd5d53db7fe1d546543d32000070916552
commit: cd3c2bdd5d53db7fe1d546543d32000070916552
branch: master
author: Zackery Spytz <zspytz at gmail.com>
committer: GitHub <noreply at github.com>
date: 2020-06-28T15:40:54+09:00
summary:

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

files:
A Misc/NEWS.d/next/Library/2020-06-25-10-11-47.bpo-31082.HsgDkx.rst
M Lib/functools.py
M Modules/_functoolsmodule.c

diff --git a/Lib/functools.py b/Lib/functools.py
index 5cab497d26403..b1f1fe8d9a6f2 100644
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -236,14 +236,14 @@ def __ge__(self, other):
 
 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,
-    from left to right, so as to reduce the sequence to a single value.
-    For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates
+    Apply a function of two arguments cumulatively to the items of a sequence
+    or iterable, from left to right, so as to reduce the iterable to a single
+    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
-    of the sequence in the calculation, and serves as a default when the
-    sequence is empty.
+    of the iterable in the calculation, and serves as a default when the
+    iterable is empty.
     """
 
     it = iter(sequence)
@@ -252,7 +252,8 @@ def reduce(function, sequence, initial=_initial_missing):
         try:
             value = next(it)
         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:
         value = initial
 
diff --git a/Misc/NEWS.d/next/Library/2020-06-25-10-11-47.bpo-31082.HsgDkx.rst b/Misc/NEWS.d/next/Library/2020-06-25-10-11-47.bpo-31082.HsgDkx.rst
new file mode 100644
index 0000000000000..9746d33a49638
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-06-25-10-11-47.bpo-31082.HsgDkx.rst
@@ -0,0 +1 @@
+Use the term "iterable" in the docstring for :func:`functools.reduce`.
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c
index 8120140afac05..bb86fe862da6d 100644
--- a/Modules/_functoolsmodule.c
+++ b/Modules/_functoolsmodule.c
@@ -679,7 +679,7 @@ functools_reduce(PyObject *self, PyObject *args)
 
     if (result == NULL)
         PyErr_SetString(PyExc_TypeError,
-                   "reduce() of empty sequence with no initial value");
+                   "reduce() of empty iterable with no initial value");
 
     Py_DECREF(it);
     return result;
@@ -692,14 +692,14 @@ functools_reduce(PyObject *self, PyObject *args)
 }
 
 PyDoc_STRVAR(functools_reduce_doc,
-"reduce(function, sequence[, initial]) -> value\n\
+"reduce(function, iterable[, initial]) -> value\n\
 \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\
-For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates\n\
+Apply a function of two arguments cumulatively to the items of a sequence\n\
+or iterable, from left to right, so as to reduce the iterable to a single\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\
-of the sequence in the calculation, and serves as a default when the\n\
-sequence is empty.");
+of the iterable in the calculation, and serves as a default when the\n\
+iterable is empty.");
 
 /* lru_cache object **********************************************************/
 



More information about the Python-checkins mailing list