You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A class pickled by value before its annotations are read loses them. #608
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).
importsubprocess, sysimportcloudpicklens= {"__name__": "not_importable"} # not importable, so the class is pickled by valueexec("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__)"fortag, blobin [("unread", unread), ("read", read)]:
out=subprocess.run([sys.executable, "-c", load], input=blob, capture_output=True, check=True)
print(tag, out.stdout.decode().strip())
#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.
changed the title [-]Incorrect behavior of annotations when they're empty.[/-][+]A class pickled by value before its annotations are read loses them.[/+]on Oct 8, 2026
Activity
[-]Incorrect behavior of annotations when they're empty.[/-][+]A class pickled by value before its annotations are read loses them.[/+]