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

未关闭
#1,363 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
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 小时
30 天内合并 PR
68

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

oracle/graalpython 的其他 Issue

查看 oracle/graalpython 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。