Skip to content

Commit e7c6310

Browse files
[3.13] Align functools.reduce() docstring with PEP-257 (GH-126045) (#126113)
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 36f8184 commit e7c6310

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

Lib/functools.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,14 @@ def reduce(function, sequence, initial=_initial_missing):
239239
"""
240240
reduce(function, iterable[, initial], /) -> value
241241
242-
Apply a function of two arguments cumulatively to the items of a sequence
243-
or iterable, from left to right, so as to reduce the iterable to a single
244-
value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates
245-
((((1+2)+3)+4)+5). If initial is present, it is placed before the items
246-
of the iterable in the calculation, and serves as a default when the
247-
iterable is empty.
242+
Apply a function of two arguments cumulatively to the items of an iterable, from left to right.
243+
244+
This effectively reduces the iterable to a single value. If initial is present,
245+
it is placed before the items of the iterable in the calculation, and serves as
246+
a default when the iterable is empty.
247+
248+
For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])
249+
calculates ((((1 + 2) + 3) + 4) + 5).
248250
"""
249251

250252
it = iter(sequence)

Modules/_functoolsmodule.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -780,12 +780,14 @@ functools_reduce(PyObject *self, PyObject *args)
780780
PyDoc_STRVAR(functools_reduce_doc,
781781
"reduce(function, iterable[, initial], /) -> value\n\
782782
\n\
783-
Apply a function of two arguments cumulatively to the items of a sequence\n\
784-
or iterable, from left to right, so as to reduce the iterable to a single\n\
785-
value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates\n\
786-
((((1+2)+3)+4)+5). If initial is present, it is placed before the items\n\
787-
of the iterable in the calculation, and serves as a default when the\n\
788-
iterable is empty.");
783+
Apply a function of two arguments cumulatively to the items of an iterable, from left to right.\n\
784+
\n\
785+
This effectively reduces the iterable to a single value. If initial is present,\n\
786+
it is placed before the items of the iterable in the calculation, and serves as\n\
787+
a default when the iterable is empty.\n\
788+
\n\
789+
For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])\n\
790+
calculates ((((1 + 2) + 3) + 4) + 5).");
789791

790792
/* lru_cache object **********************************************************/
791793

0 commit comments

Comments
 (0)