Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-102757: fix function signature mismatch forfunctools.reduce between code and documentation#102759

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
carljm merged 13 commits intopython:mainfromXuehaiPan:functools.reduce-docs
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
13 commits
Select commitHold shift + click to select a range
fb8d48e
Align signature of `functools.reduce` for Python implementation
XuehaiPanMar 16, 2023
dc418c4
Align signature of `functools.reduce` in documentation
XuehaiPanMar 16, 2023
7ec4feb
Mark all arguments in `functools.reduce` positional only
XuehaiPanMar 16, 2023
900963e
Add news entry
XuehaiPanMar 16, 2023
1f8830f
Merge branch 'main' into functools.reduce-docs
XuehaiPanMar 19, 2023
a9b6860
Revert signature change for `functools.reduce` Python implementation
XuehaiPanMar 19, 2023
af70b37
Update news entry
XuehaiPanMar 19, 2023
9886226
Merge branch 'main' into functools.reduce-docs
XuehaiPanMar 20, 2023
1157dfa
Merge branch 'main' into functools.reduce-docs
XuehaiPanMar 21, 2023
661ecc8
Merge branch 'main' into functools.reduce-docs
XuehaiPanMar 24, 2023
f24c255
Merge branch 'main' into functools.reduce-docs
XuehaiPanMar 30, 2023
9084477
Merge branch 'main' into functools.reduce-docs
XuehaiPanApr 14, 2023
c8bc13f
Merge branch 'main' into functools.reduce-docs
carljmSep 18, 2023
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 deletionsDoc/library/functools.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -403,25 +403,27 @@ The :mod:`functools` module defines the following functions:
.. versionadded:: 3.4


.. function:: reduce(function, iterable[,initializer])
.. function:: reduce(function, iterable[,initial], /)

Apply *function* of two arguments cumulatively to the items of *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)``.
The left argument, *x*, is the accumulated value and the right argument, *y*, is
the update value from the *iterable*. If the optional *initializer* is present,
the update value from the *iterable*. If the optional *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. If *initializer* is not given and
a default when the iterable is empty. If *initial* is not given and
*iterable* contains only one item, the first item is returned.

Roughly equivalent to::

def reduce(function, iterable, initializer=None):
initial_missing = object()

def reduce(function, iterable, initial=initial_missing, /):
it = iter(iterable)
ifinitializer isNone:
ifinitial isinitial_missing:
value = next(it)
else:
value =initializer
value =initial
for element in it:
value = function(value, element)
return value
Expand Down
2 changes: 1 addition & 1 deletionLib/functools.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -236,7 +236,7 @@ def __ge__(self, other):

def reduce(function, sequence, initial=_initial_missing):
"""
reduce(function, iterable[, initial]) -> value
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
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
Align function signature for ``functools.reduce`` in documentation and docstring
with the C implementation.
2 changes: 1 addition & 1 deletionModules/_functoolsmodule.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -725,7 +725,7 @@ functools_reduce(PyObject *self, PyObject *args)
}

PyDoc_STRVAR(functools_reduce_doc,
"reduce(function, iterable[, initial]) -> value\n\
"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\
Expand Down

[8]ページ先頭

©2009-2026 Movatter.jp