Repository navigation
gh-74876: Add copyreg.Proxy - #160219
Open
serhiy-storchaka wants to merge 1 commit into
Open
gh-74876: Add copyreg.Proxy#160219serhiy-storchaka wants to merge 1 commit into
serhiy-storchaka wants to merge 1 commit into
Conversation
A copyreg.Proxy is pickled as the wrapped object, which must be strongly referenced elsewhere in the same pickle. It replaces the native support of weak references in pickle: weakref.ref, WeakMethod, WeakSet, WeakValueDictionary and WeakKeyDictionary are now reduced using Proxy. The copy module supports Proxy too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
serhiy-storchaka
marked this pull request as ready for review
October 22, 2026 07:57
serhiy-storchaka
requested review from
AA-Turner and
kumaraditya303
as code owners
October 22, 2026 07:57
Documentation build overview
4 files changed± library/copyreg.html± library/weakref.html± whatsnew/3.16.html± whatsnew/changelog.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
copyreg.Proxy(obj)is a wrapper that is pickled as the wrapped object. Like the referent of a weak reference, the wrapped object must be strongly referenced elsewhere in the same pickle; otherwise pickling raisesPicklingError. Reduction functions can use it to pickle objects to which the reconstructed object only holds weak references.It replaces the native support of weak references added in #153818: the picklers now only know about
Proxy, andweakref.ref,WeakMethod,WeakSet,WeakValueDictionaryandWeakKeyDictionaryare reduced using it. This has two advantages:WeakMethodpickle the weakly referenced objects themselves instead of weak references to them.weakref._dead_refand private reconstructors). A dead reference is pickled as a reference to an empty set.The
copymodule supportsProxytoo:copy.copy()returns the wrapped object andcopy.deepcopy()returns its deep copy.🤖 Generated with Claude Code