Attempting to assign an infinte generator to an extended slice hangs indefinitely instead of raising ValueError
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
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 calling next() until StopIteration 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:
class MyGen:
def __iter__(self):
while True:
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 2
l[::2] = MyGen() # hangs indefinitely despite returning more than 2 values
CPython versions tested on:
3.14
Operating systems tested on:
macOS
Linked PRs
- gh-146272
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
issue にある拡張スライス代入の例でハングを再現し、次に iterable を消費する builtin の拡張スライス代入経路を追跡します。無限ジェネレーターを対象とするリグレッションテストを追加し、スライスの長さを超えた時点で代入が ValueError を発生させることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100