Skip to content

itertools: fix signature of accumulate #4933

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

Merged
merged 3 commits into from
Jan 14, 2021
Merged

Conversation

hauntsaninja
Copy link
Collaborator

Resolves #4888

Comment on lines 24 to 28
def accumulate(iterable: Iterable[_T], func: Optional[Callable[[_T, _T], _T]] = ...) -> Iterator[_T]: ...
@overload
def accumulate(iterable: Iterable[_T], func: Callable[[_S, _T], _S], initial: Optional[_S]) -> Iterator[_S]: ...
def accumulate(
iterable: Iterable[_T], func: Optional[Callable[[_S, _T], _S]] = ..., *, initial: Optional[_S] = ...
) -> Iterator[_S]: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two overloads seem to overlap. Also, the second overload can't work if func is None, because _S is then undefined. I would suggest to use func: None = ... for the first (which also needs to include initial), and func: Callable[etc] (without default) for the second overload. I think this should also cover all cases?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that looks right to me too

@srittau srittau merged commit c893857 into python:master Jan 14, 2021
@hauntsaninja hauntsaninja deleted the iter branch January 14, 2021 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

For itertools.accumulate, erroneously: requires func if initial specified; allows initial to be positional
2 participants