gh-146268: Fix case where assigning an infinite generator to an extend slice hangs instead of raising ValueError#146272
Open
csm10495 wants to merge 5 commits intopython:mainfrom
Open
gh-146268: Fix case where assigning an infinite generator to an extend slice hangs instead of raising ValueError#146272csm10495 wants to merge 5 commits intopython:mainfrom
csm10495 wants to merge 5 commits intopython:mainfrom
Conversation
…-146268) When assigning an arbitrary iterable to an extended slice (step != 1), use bounded iteration to collect at most slicelength + 1 items instead of eagerly consuming the entire iterable via PySequence_Fast. This prevents infinite iterators from hanging indefinitely. The slice length is recomputed after consuming the iterable to handle pathological iterators that mutate the list during iteration. Co-authored-by: csm10495 <5749838+csm10495@users.noreply.github.com> Agent-Logs-Url: https://github.com/csm10495/cpython/sessions/996cabbe-7dc6-4faa-b95b-31907ef41b20
Co-authored-by: csm10495 <5749838+csm10495@users.noreply.github.com> Agent-Logs-Url: https://github.com/csm10495/cpython/sessions/996cabbe-7dc6-4faa-b95b-31907ef41b20
Co-authored-by: csm10495 <5749838+csm10495@users.noreply.github.com> Agent-Logs-Url: https://github.com/csm10495/cpython/sessions/88e0f16d-fa86-4769-bb78-fa43eb6cc308
Co-authored-by: csm10495 <5749838+csm10495@users.noreply.github.com> Agent-Logs-Url: https://github.com/csm10495/cpython/sessions/88e0f16d-fa86-4769-bb78-fa43eb6cc308
Co-authored-by: csm10495 <5749838+csm10495@users.noreply.github.com> Agent-Logs-Url: https://github.com/csm10495/cpython/sessions/2a4b3921-dacb-4e10-8633-d2bf840cdc99
|
The following commit authors need to sign the Contributor License Agreement: |
Member
|
This isn't ready yet. The error message from this approach leaks internal implementation details. |
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.
gh-146268: Fix case where assigning an infinite generator to an extend slice hangs instead of raising ValueError
Also add in some unit tests and a blurb entry.
step != 1is special since we will only perform that assignment if the size of the right matches that of the left. An infinitely sized right hand side can never fill in a (non infinite) left hand side. So we calculate out the left hand side's slice length, then use that to determine if we went over (+1 the left hand's length).