From 5f9a94e07a023beb151ee5b0a831032be7b662dd Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Mon, 9 Jun 2025 06:27:43 +0300 Subject: [PATCH 1/2] gh-135282: correct itertools.accumulate() signature in sphinx docs Now it's in sync with docstring/inspect output. --- Doc/library/itertools.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index 00925ae920aad9..94ca619ab9714d 100644 --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -93,12 +93,12 @@ streams of infinite length, so they should only be accessed by functions or loops that truncate the stream. -.. function:: accumulate(iterable[, function, *, initial=None]) +.. function:: accumulate(iterable, func=None, *, initial=None) Make an iterator that returns accumulated sums or accumulated results from other binary functions. - The *function* defaults to addition. The *function* should accept + The *func* defaults to addition. The *func* should accept two arguments, an accumulated total and a value from the *iterable*. If an *initial* value is provided, the accumulation will start with @@ -126,9 +126,9 @@ loops that truncate the stream. total = function(total, element) yield total - To compute a running minimum, set *function* to :func:`min`. - For a running maximum, set *function* to :func:`max`. - Or for a running product, set *function* to :func:`operator.mul`. + To compute a running minimum, set *func* to :func:`min`. + For a running maximum, set *func* to :func:`max`. + Or for a running product, set *func* to :func:`operator.mul`. To build an `amortization table `_, accumulate the interest and apply payments: @@ -152,7 +152,7 @@ loops that truncate the stream. .. versionadded:: 3.2 .. versionchanged:: 3.3 - Added the optional *function* parameter. + Added the optional *func* parameter. .. versionchanged:: 3.8 Added the optional *initial* parameter. From 40f6959de412dc45e5beeba0046474e5305e1e63 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Mon, 9 Jun 2025 06:36:14 +0300 Subject: [PATCH 2/2] + example --- Doc/library/itertools.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index 94ca619ab9714d..6fbeb3c1bd3ac5 100644 --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -107,7 +107,7 @@ loops that truncate the stream. Roughly equivalent to:: - def accumulate(iterable, function=operator.add, *, initial=None): + def accumulate(iterable, func=operator.add, *, initial=None): 'Return running totals' # accumulate([1,2,3,4,5]) → 1 3 6 10 15 # accumulate([1,2,3,4,5], initial=100) → 100 101 103 106 110 115 @@ -123,7 +123,7 @@ loops that truncate the stream. yield total for element in iterator: - total = function(total, element) + total = func(total, element) yield total To compute a running minimum, set *func* to :func:`min`.