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
gh-74876: Support pickling weak references and weak containers
* weakref.ref is pickled by the pickler itself, as weakref.ref(referent).
The referent is pickled weakly: it must be strongly referenced elsewhere
in the same pickle, otherwise pickling raises PicklingError. A reference
to a dead object is pickled by name, as the new weakref._dead_ref
singleton. The callback is not preserved.
* WeakMethod can now be pickled and copied: it reduces to a weak reference
to the object the method is bound to.
* WeakSet, WeakValueDictionary and WeakKeyDictionary can now be pickled:
they reduce their elements, values and keys to weak references. WeakSet
can now also be copied.
Only existing opcodes are used, so no new pickle protocol is needed.
The detection of weak references without a strong reference in the pickle
is conservative: valid but exotic reference graphs may be refused.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
0 commit comments