[Bug]: Container iterators share one `iterator` type

オープン
#1,361 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
java, python
領域
backend

調査の方向性

Start in PFactory.java where the str, bytes, list, tuple, range and set iterators are all created with PIterator, and in IteratorBuiltins where the extendClasses list is defined. Then check the two SequenceStorageNodes.java checks that recognise builtin iterators by PIterator. Done when type(iter([])).__name__ gives list_iterator, type(reversed([])) is reversed is False, and the table in the issue matches CPython 3.12/3.13.

索引モデルが issue の本文から書いたものです。

説明

bug
Describe the bug

The iterators of str, bytes, bytearray, list, tuple, range and set are all instances of one type named iterator, and reversed() of a list is a reversed object. CPython has one iterator type per container, so type(iter([])) and type(iter(())) are different types named list_iterator and tuple_iterator.

Operating system

macOS

CPU architecture

ARM64

GraalPy version

master 3289197e63 (Python 3.13.14), built with mx python-jvm

JDK version

No response

Context configuration

No response

Steps to reproduce
Expression GraalPy CPython
type(iter('a')).__name__ iterator str_ascii_iterator
type(iter(b'a')).__name__ iterator bytes_iterator
type(iter([])).__name__ iterator list_iterator
type(iter(())).__name__ iterator tuple_iterator
type(iter([])) is type(iter(())) True False
type(reversed([])) is reversed True False
Expected behavior

The CPython column above (3.12.13 and 3.13.14).

Stack trace

Additional context
Root Cause

PFactory creates the iterators of str, bytes, bytearray, list, tuple, range and set with the one class PIterator, and list.__reversed__ returns a reversed object (PFactory.java#L1018-L1080). CPython has a type object per container, for example list_iterator and list_reverseiterator (listobject.c#L3195, #L3341), and picks str_ascii_iterator or str_iterator per string (unicodeobject.c#L15490-L15495). dict and its views, memoryview and array already have their own iterator types on GraalPy.

Fix Suggestion

Add the missing types to PythonBuiltinClassType with IteratorBuiltins.SLOTS and let each factory in PFactory take its class from the caller, keeping PIterator for the __getitem__ protocol iterator. The checks that recognise a builtin iterator by PIterator (SequenceStorageNodes.java#L4361, #L4418) and the extendClasses list of IteratorBuiltins have to accept the new classes.

主要言語
Python
スター
1.7k
フォーク
167
平均マージ
3日 11時間
マージ済み PR(30日)
68

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

oracle/graalpython のほかの issue

oracle/graalpython の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。