A class pickled by value before its annotations are read loses them.
Los mantenedores suelen responder en 16 días
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 67/100
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
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de cloudpipe/cloudpickle
-
Bug: unguarded dict.pop() in _function_setstate causes KeyError crash on crafted pickle (regression from c6f8cd4)Posiblemente ocupada @soodoku la tomó hace 85 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
cloudpipe/cloudpickle#593 · 1 comentario ·
Los mantenedores suelen responder en 16 días
-
Globals read only inside a class body defined in a by-value function are not pickled (NameError after loading)Posiblemente ocupada @Eryx-Z la tomó hace 4 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
cloudpipe/cloudpickle#609 · 1 comentario ·
Los mantenedores suelen responder en 16 días
-
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
cloudpipe/cloudpickle#595 ·
Los mantenedores suelen responder en 16 días
-
cloudpickle is not compatible with PyPy 7.3.22Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 65/100
cloudpipe/cloudpickle#592 · 2 comentarios ·
Los mantenedores suelen responder en 16 días
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
cloudpipe/cloudpickle#589 ·
Los mantenedores suelen responder en 16 días
Todos los issues de cloudpipe/cloudpickle
Issues similares
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
Los mantenedores suelen responder en 1 día
-
good first issue module-baseline needs triage ux
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
darnitdevorg/darnit#650 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
nyjc-computing/campus#938 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
nf-osi/nf-metadata-dictionary#1027 ·
Los mantenedores suelen responder en 1 día
-
bug documentation
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
qatrackplus/qatrackplus#913 ·
Los mantenedores suelen responder en 3 días