-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-125916: Allow functools.reduce 'initial' to be a keyword argument #125917
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
Changes from 5 commits
2b57bd0
b7617c8
47abbd1
2fc8841
7b795ba
11e7d13
25c35e3
ede87bf
d8a5538
84f0a04
8b3c2e5
2705ffa
0d81eb2
46979d0
7e05bc7
f1b5994
7cc052f
4130df8
b4fb15c
0cda3b6
85e5012
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -236,7 +236,7 @@ def __ge__(self, other): | |||||
|
|
||||||
| def reduce(function, sequence, initial=_initial_missing): | ||||||
| """ | ||||||
| reduce(function, iterable[, initial], /) -> value | ||||||
| reduce(function, iterable, /, initial=None) -> value | ||||||
|
||||||
| reduce(function, iterable, /, initial=None) -> value | |
| reduce(function, iterable, /, initial=...) -> value |
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.
See PEP 661:)
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.
But the sentinel is private and doesn't even exist in the C implementation. Ellipsis is frequently used for unspecified default values in typeshed. We could use multiple signatures though.
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.
But the sentinel is private and doesn't even exist in the C implementation.
It's easy to add, see #125917 (comment)
Ellipsis is frequently used for unspecified default values in typeshed.
We could use multiple signatures though.
Yes, I think it's fine for the sphinx docs. But help will looks like this (as for pure-Python version):
>>> help(functools.reduce)
Help on built-in function reduce in module _functools:
reduce(function, iterable, /,
initial=_functools._initial_missing)
Apply a function of two arguments cumulatively to an iterable, from left to right.
[...]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.
I don't think I've ever seen =... in the docs. Do we have precedent for that?
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.
It seems like the signature is giving inspect a hard time. But it is autogenerated by AC. Did I do something wrong?
reduce(function, iterable, /,
initial=_functools._initial_missing)
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.
But the sentinel is private and doesn't even exist in the C implementation. Ellipsis is frequently used for unspecified default values in typeshed. We could use multiple signatures though.
Multiple signatures for a docs sounds like a good solution.
Using ... for default values is essentially the same as using None, and it's just wrong since users can pass ... as the initial value.
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.
I don't think I've ever seen =... in the docs. Do we have precedent for that?
Yeah, e.g. for the int.from_bytes, for example.
it seems like the signature is giving inspect a hard time. But it is autogenerated by AC. Did I do something wrong?
First, note that reduce() has no correct signature in the current main.
Now AC adds one, but it can't be parsed by inspect._signature_fromstr(): this helper has own opinion on what can be specified as a default value (e.g. it can't be a complex number).
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Allow the *initial* argument of :func:`functools.reduce` to be a keyword. | ||
sayandipdutta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Patch by Sayandip Dutta. | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.