Skip to content

[3.13] Align functools.reduce() docstring with PEP-257 (GH-126045) #126113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions Lib/functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,14 @@ def reduce(function, sequence, initial=_initial_missing):
"""
reduce(function, iterable[, initial], /) -> value

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 iterable in the calculation, and serves as a default when the
iterable is empty.
Apply a function of two arguments cumulatively to the items of an iterable, from left to right.

This effectively reduces the iterable to a single value. If initial is present,
it is placed before the items of the iterable in the calculation, and serves as
a default when the iterable is empty.

For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])
calculates ((((1 + 2) + 3) + 4) + 5).
"""

it = iter(sequence)
Expand Down
14 changes: 8 additions & 6 deletions Modules/_functoolsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -780,12 +780,14 @@ functools_reduce(PyObject *self, PyObject *args)
PyDoc_STRVAR(functools_reduce_doc,
"reduce(function, iterable[, initial], /) -> value\n\
\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 iterable in the calculation, and serves as a default when the\n\
iterable is empty.");
Apply a function of two arguments cumulatively to the items of an iterable, from left to right.\n\
\n\
This effectively reduces the iterable to a single value. If initial is present,\n\
it is placed before the items of the iterable in the calculation, and serves as\n\
a default when the iterable is empty.\n\
\n\
For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])\n\
calculates ((((1 + 2) + 3) + 4) + 5).");

/* lru_cache object **********************************************************/

Expand Down
Loading