Uh oh!
There was an error while loading. Please reload this page.
gh-102757: fix function signature mismatch for functools.reduce between code and documentation - #102759
Conversation
Uh oh!
There was an error while loading. Please reload this page.
XuehaiPan
commented
Mar 22, 2023
May also need to backport to Python 3.10 and 3.11. This documentation issue is causing real-world problems. Such as: |
arhadthedev
commented
Mar 22, 2023
@rhettinger (as a functools expert) |
carljm
left a comment
There was a problem hiding this comment.
Thanks! It makes sense for the CPython
documentation and docstring of functools.reduce to align with the implementation that is always used in CPython.
XuehaiPan
commented
Sep 18, 2023
Gentle ping for this. Any updates? |
bedevere-bot
commented
Sep 18, 2023
|
bedevere-bot
commented
Sep 18, 2023
|
bedevere-bot
commented
Sep 18, 2023
|
AA-Turner
commented
Sep 19, 2023
@carljm should we backport the docs part of this PR? |
carljm
commented
Sep 20, 2023
@AA-Turner Sure, we can. I don't think it's important, but I guess it's possible it could reduce conflict in some other backport in future. |
…e` between code and documentation (python#102759)
…116398) The `initial` argument in `functools.reduce` can be `None`. ```python initial_missing = object() def reduce(function, iterable, initial=initial_missing, /): it = iter(iterable) if initial is initial_missing: value = next(it) else: value = initial for element in it: value = function(value, element) return value ``` Reference: - python/cpython#102759 Pull Request resolved: #116398 Approved by: https://github.com/Skylion007
Summary: The `initial` argument in `functools.reduce` can be `None`. ```python initial_missing = object() def reduce(function, iterable, initial=initial_missing, /): it = iter(iterable) if initial is initial_missing: value = next(it) else: value = initial for element in it: value = function(value, element) return value ``` Reference: - python/cpython#102759 X-link: pytorch/pytorch#116398 Approved by: https://github.com/Skylion007 Reviewed By: izaitsevfb, jeanschmidt Differential Revision: D52424773 fbshipit-source-id: 36d3a6f5f5786350fe8c325773deb135ccbd48e9
functools.reducein Python implementation and documentation with the C implementation./to mark all arguments are positional only.functools.reducebetween C implementation, Python implementation, and online documentaion #102757