Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
csm10495:copilot/fix-bug-146268
Open

gh-146268: Fix case where assigning an infinite generator to an extend slice hangs instead of raising ValueError#146272
csm10495 wants to merge 5 commits intopython:mainfrom
csm10495:copilot/fix-bug-146268

Conversation

@csm10495
Copy link
Contributor

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 != 1 is 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).

@python-cla-bot
Copy link

python-cla-botbot commentedMar 22, 2026
edited
Loading

All commit authors signed the Contributor License Agreement.

CLA signed

@johnslavik
Copy link
Member

johnslavik commentedMar 22, 2026
edited
Loading

This isn't ready yet.

❯ py t.pyTraceback (most recent call last):  File "/Users/bartosz.slawecki/Python/cpython/t.py", line 10, in <module>    l[::2] = MyGen()    ~^^^^^ValueError: attempt to assign sequence of size 3 to extended slice of size 2

The error message from this approach leaks internal implementation details.MyGen() (from the PR) is not a sequence of size 3, it's a generator.

csm10495 reacted with thumbs up emoji

@csm10495csm10495force-pushed thecopilot/fix-bug-146268 branch from3b29ec0 to26fd46eCompareMarch 22, 2026 14:18
@csm10495
Copy link
ContributorAuthor

@johnslavik updated based off your feedback. Please check again.

@csm10495csm10495 marked this pull request as ready for reviewMarch 22, 2026 14:58
Copy link
Member

@picnixzpicnixz left a comment

Choose a reason for hiding this comment

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

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

}
elseif (step!=1&&
!PyList_CheckExact(value)&&
!PyTuple_CheckExact(value))
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

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.

@bedevere-app
Copy link

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 phraseI have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@csm10495
Copy link
ContributorAuthor

csm10495 commentedMar 22, 2026
edited
Loading

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

For me on 3.14.3 and on the latest head of this branch this scenario works the same:

In [1]: a = list(range(10))In [2]: aOut[2]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]In [3]: a[::2] = a---------------------------------------------------------------------------ValueError                                Traceback (most recent call last)Cell In[3], line 1----> 1 a[::2] = aValueError: attempt to assign sequence of size 10 to extended slice of size 5In [4]:

tbd on bytearray and arrray.array

@csm10495csm10495force-pushed thecopilot/fix-bug-146268 branch from8f1056c toc1ad027CompareMarch 22, 2026 17:06
@csm10495csm10495 requested a review frompicnixzMarch 22, 2026 17:07
@csm10495
Copy link
ContributorAuthor

@picnixz I think i addressed your points. Thanks!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@ericsnowcurrentlyericsnowcurrentlyAwaiting requested review from ericsnowcurrently

@sethmlarsonsethmlarsonAwaiting requested review from sethmlarson

@picnixzpicnixzAwaiting requested review from picnixz

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@csm10495@johnslavik@picnixz

[8]ページ先頭

©2009-2026 Movatter.jp