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

Đang mở
#1,363 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
Nửa ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java, python
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
1.7k
Fork
167
Merge trung bình
3 ngày 11 giờ
Pull request đã merge (30 ngày)
68

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của oracle/graalpython

Tất cả issue của oracle/graalpython

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.