Skip to content

Commit a8472fd

Browse files
[3.12] Align functools.reduce() docstring with PEP-257 (GH-126045) (#126114)
Yak-shave in preparation for Argument Clinic adaption in gh-125999. (cherry picked from commit 9b14083) Co-authored-by: Sergey B Kirpichev <[email protected]>
1 parent 385fa83 commit a8472fd

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

Lib/functools.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,14 @@ def reduce(function, sequence, initial=_initial_missing):
238238
"""
239239
reduce(function, iterable[, initial]) -> value
240240
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
244-
((((1+2)+3)+4)+5). If initial is present, it is placed before the items
245-
of the iterable in the calculation, and serves as a default when the
246-
iterable is empty.
241+
Apply a function of two arguments cumulatively to the items of an iterable, from left to right.
242+
243+
This effectively reduces the iterable to a single value. If initial is present,
244+
it is placed before the items of the iterable in the calculation, and serves as
245+
a default when the iterable is empty.
246+
247+
For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])
248+
calculates ((((1 + 2) + 3) + 4) + 5).
247249
"""
248250

249251
it = iter(sequence)

Modules/_functoolsmodule.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -734,12 +734,14 @@ functools_reduce(PyObject *self, PyObject *args)
734734
PyDoc_STRVAR(functools_reduce_doc,
735735
"reduce(function, iterable[, initial]) -> value\n\
736736
\n\
737-
Apply a function of two arguments cumulatively to the items of a sequence\n\
738-
or iterable, from left to right, so as to reduce the iterable to a single\n\
739-
value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates\n\
740-
((((1+2)+3)+4)+5). If initial is present, it is placed before the items\n\
741-
of the iterable in the calculation, and serves as a default when the\n\
742-
iterable is empty.");
737+
Apply a function of two arguments cumulatively to the items of an iterable, from left to right.\n\
738+
\n\
739+
This effectively reduces the iterable to a single value. If initial is present,\n\
740+
it is placed before the items of the iterable in the calculation, and serves as\n\
741+
a default when the iterable is empty.\n\
742+
\n\
743+
For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])\n\
744+
calculates ((((1 + 2) + 3) + 4) + 5).");
743745

744746
/* lru_cache object **********************************************************/
745747

0 commit comments

Comments
 (0)