-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-135282: change documented signature of itertools.accumulate()
#135283
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
Open
skirpichev
wants to merge
5
commits into
python:main
Choose a base branch
from
skirpichev:fix-accumulate-signature/135282
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+5
β3
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5f9a94e
gh-135282: correct itertools.accumulate() signature in sphinx docs
skirpichev 40f6959
+ example
skirpichev 5d217fb
Merge branch 'master' into fix-accumulate-signature/135282
skirpichev fbb34f6
address review: change example
skirpichev 051aba8
XXX revert func->function in description?
skirpichev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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 think this is a better alternative, if we decide to change anything.
None
is misleading: the prose notes that the function defaults to addition. This is a good example of the function de facto having multiple signatures. The simple case is summation, the intermediate case is summation from an initial condition, and the advanced case is a custom accumulator.The linked issue is a user using keyword-arguments for both iterable and func, which should probably be discouraged. I personally find it clearer to have 'function' throughout in the prose documentation, and I wonder if func is less clear to non-native speakers of English.
Arguably, it should note that initial is only used if not
None
, too, but this is somewhat obvious from context.A second, simpler suggestion would be as follows:
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.
Yet it has one.
Both argument names are part of the API.
We can change argument name, but it looks as a compatibility break for me.
Sorry, neither suggestion is acceptable for me.
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.
This suggestion is IMO the best because it hides the implementation detail of
func=None
.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.
"reference material should prioritize precision and completeness" (c)
Proposed changes aren't precise. Are you suggesting to change actual function signature?
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.
No, I meant to hide the implementation detail. I don't think anyone is expected to do
accumulate(iterable, None)
(the current docs do not expose that detail for instance).Even if the EB's decision is about "reference material should prioritize precision and completeness", it's a "SHOULD" not a "MUST", which I consider it as a recommendation and not a strict rule. When it comes at the cost of exposing implementation details, I think it's better not to.
Now, itertools.groupby explicitly documents
key
as being allowed to beNone
and says:So, if you want to keep
func=None
, I'd suggest stating thatNone
defaults to addition. This would avoid two signatures in the docs and would be aligned withitertools.groupby
.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.
Given the fate of #131885 - I guess you are right :(
Where is the difference between implementation details and API? These "details" could be discovered anyway by standard tools for introspection.
Now function has a valid (for the inspect module) signature. Why should we lie in docs, that func=None is not accepted?
But that seems to be documented: "The func defaults to addition." (and default argument for func shown in the signature)