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

Attempting to assign an infinte generator to an extended slice hangs indefinitely instead of raising ValueError #146268

Open
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error
@Next-Door-Tech

Description

@Next-Door-Tech

Bug report

Bug description:

For builtin types which support assignment to extended slices (i.e. slices with a step other than 1), the length of the iterable being assigned from must be equal to the length of the slice being assigned to. However, Python appears to determine the length of the iterable by repeatedly callingnext() untilStopIteration is raised.

In the event that an object never raises StopIteration, this creates an infinite evaluation loop, even though it should be apparent that the two sizes are not equal once the size of the slice has been exceeded. See the example below:

classMyGen:def__iter__(self):whileTrue:yield"foo"l= [0,1,2,3]l[::2]=range(10)# raises ValueError: attempt to assign sequence of size 10 to extended slice of size 2l[::2]=MyGen()# hangs indefinitely despite returning more than 2 values

CPython versions tested on:

3.14

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2026 Movatter.jp