Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

A class pickled by value before its annotations are read loses them.

Ouverte
#608 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 16 jours

@pralav-25 y travaille déjà.

Depuis le 8/10/2026.

  • #610 par @pralav-25 — ouverte

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
67/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
python
Domaine
backend

Piste de recherche

Start in cloudpickle/cloudpickle.py at _class_getstate and _class_setstate, then compare the class annotation handling with the snapshot behavior described for #603. Reproduce with the provided Python 3.14 example, checking both unread and already-read annotations after unpickling. Done when a by-value pickled class preserves its annotations even when they had not been read before pickling.

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

Description

A summary of the problem from a bot below:

On Python 3.14, a class pickled by value before its annotations have ever been read unpickles with annotations == {}. This happens on cloudpickle 3.1.2, on #603's head (0f652a6), and on master (4af5936).

import subprocess, sys
import cloudpickle

ns = {"__name__": "not_importable"}  # not importable, so the class is pickled by value
exec("class C:\n    x: int\n", ns)
unread = cloudpickle.dumps(ns["C"])
ns["C"].__annotations__  # first read fills __annotations_cache__
read = cloudpickle.dumps(ns["C"])

load = "import pickle, sys; print(pickle.loads(sys.stdin.buffer.read()).__annotations__)"
for tag, blob in [("unread", unread), ("read", read)]:
    out = subprocess.run([sys.executable, "-c", load], input=blob, capture_output=True, check=True)
    print(tag, out.stdout.decode().strip())

Cause: _class_getstate (https://github.com/cloudpipe/cloudpickle/blob/4af5936/cloudpickle/cloudpickle.py#L792-L797) does clsdict.pop("annotate_func", None), with the comment "Python will recreate it when annotations is accessed at unpickling time". Python does not recreate it. Before the first read, the class dict holds only annotate_func, so the pickled state has no annotations at all. After a read, annotations_cache exists and survives. The note in _class_setstate (L1213 (https://github.com/cloudpipe/cloudpickle/blob/4af5936/cloudpickle/cloudpickle.py#L1213-L1215)) makes the same assumption.

#603 (crash report in #585) snapshots annotations for by-value annotate functions. The class path needs the same snapshot: in _class_getstate, evaluate the annotations (for example annotationlib.get_annotations(obj)) into annotations_cache before popping annotate_func. Dataclasses are not affected, because the decorator reads the annotations at class creation. Plain classes whose annotations are first read after pickling (typing introspection, pydantic-style consumers on the worker) lose them silently.

Langage dominant
Python
Étoiles
1.9k
Forks
206
Métriques de merge des PR
Aucune PR mergée en 30 j

Préparer son environnement

Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.

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 cloudpipe/cloudpickle

Toutes les issues de cloudpipe/cloudpickle

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.