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

Ouverte
#1,363 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
Une demi-journée
Accessibilité débutants
55/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
java, python
Domaine
backend

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
Python
Étoiles
1.7k
Forks
167
Merge moyen
3 j 11 h
PR mergées (30 j)
68

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de oracle/graalpython

Toutes les issues de oracle/graalpython

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.