[Bug]: `accumulate.__reduce__()` builds its `chain` from a list when the running total is `None`

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

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

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

評価

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

調査の方向性

Start in graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/AccumulateBuiltins.java, in the ReduceNode for both the None-total and initial branches. Run the reproduction from the issue and compare source.reduce() with CPython 3.12/3.13. Done when the GraalPy output has the same shape as CPython's chain((None,), it) and pickle.dumps(a) gives identical bytes.

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

説明

bug
Describe the bug

accumulate.__reduce__() builds the replacement chain from a list of iterators when the running total is None, where CPython calls chain((None,), it). The restored iterator yields the same values, but pickle.dumps() gives different bytes.

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

This applies to the 3.12 and 3.13 lines only: itertools pickle support is deprecated there and removed in 3.14.

import itertools

a = itertools.accumulate([1, 2, 3], lambda x, y: None)
next(a)
next(a)
chain = a.__reduce__()[1][0].__reduce__()[1][0]
source = chain.__reduce__()[2][0]
Expression GraalPy CPython
source.__reduce__() (<built-in function iter>, ([<iterator object at 0x...>, <iterator object at 0x...>],), 0) (<built-in function iter>, (((None,), <list_iterator object at 0x...>),), 0)
Expected behavior

The CPython column above (3.12.13 and 3.13.14).

Stack trace

Additional context
Root Cause

When the running total is None, accumulate.__reduce__ fills the replacement chain by hand, with a source that iterates over a list holding iter([None]) and the underlying iterator. CPython calls chain((None,), it), whose source iterates over the argument tuple. The restored iterator yields the same values, but pickle.dumps(a) gives different bytes. The initial branch just above builds its chain by hand in the same way.

Fix Suggestion

In both branches of ReduceNode, set the chain's source to an iterator over the tuple ((value,), iterable) and leave its active iterator unset.

主要言語
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 を短くまとめたダイジェスト。