[issue43252] deepcopy of weakref proxies

Konrad Schwarz report at bugs.python.org
Thu Apr 15 04:26:12 EDT 2021


Konrad Schwarz <konrad.schwarz at gmail.com> added the comment:

Well, in the example code, the memo dictionary contains the (hard) reference to newly created objects but ultimately, at the close of the deepcopy, the objects are (hard) referenced using the normal "child" attributes.

I don't however know how this would work if this was implemented within the weakref code but I expect that their __deepcopy__ method also has access to the memo variable.  If, at the close of deepcopy and the destruction of memo, no (hard) references exist to an object, then it would be collected, but that matches standard weak reference semantics.

Even if it were not possible to solve this programmatically within Python, I think the problem (and e.g. the workaround given below) should be mentioned in the documentation of deepcopy and/or weakref.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43252>
_______________________________________


More information about the Python-bugs-list mailing list