Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto
#608 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 16 días

@pralav-25 ya está trabajando en esto.

Desde el 8/10/2026.

  • #610 de @pralav-25 — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
67/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
1.9k
Forks
206
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de cloudpipe/cloudpickle

Todos los issues de cloudpipe/cloudpickle

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.