gh-146268: Fix case where assigning an infinite generator to an extend slice hangs instead of raising ValueError#146272
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
Conversation
|
This isn't ready yet. The error message from this approach leaks internal implementation details. |
3b29ec0 to
26fd46e
Compare
|
@johnslavik updated based off your feedback. Please check again. |
picnixz
left a comment
There was a problem hiding this comment.
How does bytearray and array.array handle those cases? likewise what about assigning with itself? does it change the current behavior? a[::2] = a should not be behave differently or if so we should test it
| } | ||
| else if (step != 1 && | ||
| !PyList_CheckExact(value) && | ||
| !PyTuple_CheckExact(value)) |
There was a problem hiding this comment.
Don't we have an FastSequence check for that? (fast sequences are lists or tuples). Also we should not hit this path if we have a known length.
There was a problem hiding this comment.
I don't think we have a way to check if it is a fast seq vs trying to create a new one. Agreed on the second part.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
For me on 3.14.3 and on the latest head of this branch this scenario works the same: tbd on bytearray and arrray.array |
8f1056c to
c1ad027
Compare
|
@picnixz I think i addressed your points. Thanks! |
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).