Repository navigation
gh-161004: Fixed functools.reduce where it calls iter() twice - #161015
Closed
NotorandXor256 wants to merge 8 commits into
Closed
NotorandXor256 wants to merge 8 commits into
NotorandXor256 wants to merge 8 commits into
Conversation
Documentation build overview
|
Member
|
You have lots of unrelated changes. I suggest you open a new PR without those un-necssary changes from other PRs |
Member
|
(checkout from a fresh main that is not tainted by commits not in origin/main) |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #161004
This PR fix functools.reduce.The C functools_reduce calls PyObject_GetIter(seq) once and then only PyIter_Next(it). The Python version calls iter(sequence) and then for element in it:, which calls iter() again on the iterator.
this PR fix this behavior by change for loop
for element in it:to while loop. While loop is terminatednext(element)throw a StopIteration exception and error handle it and break the loopthis PR also add a test and change the documentation
functools.reducecallsiter()twice, unlike the C implementation #161004