-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-102757: fix function signature mismatch for functools.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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
May also need to backport to Python 3.10 and 3.11. This documentation issue is causing real-world problems. Such as: |
@rhettinger (as a functools expert) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! It makes sense for the CPython
documentation and docstring of functools.reduce
to align with the implementation that is always used in CPython.
Gentle ping for this. Any updates? |
|
|
|
@carljm should we backport the docs part of this PR? |
@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.reduce
in Python implementation and documentation with the C implementation./
to mark all arguments are positional only.functools.reduce
between C implementation, Python implementation, and online documentaion #102757