Skip to content

Commit c3664b4

Browse files
skirpichevebonnal
authored andcommitted
Align functools.reduce() docstring with PEP-257 (python#126045)
Yak-shave in preparation for Argument Clinic adaption in pythongh-125999.
1 parent b32564e commit c3664b4

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
@@ -1009,12 +1009,14 @@ functools_reduce(PyObject *self, PyObject *args)
10091009
PyDoc_STRVAR(functools_reduce_doc,
10101010
"reduce(function, iterable[, initial], /) -> value\n\
10111011
\n\
1012-
Apply a function of two arguments cumulatively to the items of a sequence\n\
1013-
or iterable, from left to right, so as to reduce the iterable to a single\n\
1014-
value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates\n\
1015-
((((1+2)+3)+4)+5). If initial is present, it is placed before the items\n\
1016-
of the iterable in the calculation, and serves as a default when the\n\
1017-
iterable is empty.");
1012+
Apply a function of two arguments cumulatively to the items of an iterable, from left to right.\n\
1013+
\n\
1014+
This effectively reduces the iterable to a single value. If initial is present,\n\
1015+
it is placed before the items of the iterable in the calculation, and serves as\n\
1016+
a default when the iterable is empty.\n\
1017+
\n\
1018+
For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])\n\
1019+
calculates ((((1 + 2) + 3) + 4) + 5).");
10181020

10191021
/* lru_cache object **********************************************************/
10201022

0 commit comments

Comments
 (0)