[issue14577] pickling uses __class__ so you can't pickle proxy/mock objects that pretend to be other objects
report at bugs.python.org
Sat Apr 14 13:52:58 CEST 2012
Michael Foord <michael at voidspace.org.uk> added the comment:
Nick - in general proxy objects have a *reference* to their target (weakref being somewhat of a special case), and pickle can already handle multiple references to the same target when deserializing an object graph. So I don't see that argument holding water for the general case.
I also challenge the assertion that for a weakref proxy "you never want to serialise the proxy, you want to serialise the original object". Why? If the weakref proxy could be serialized and deserialized including the target, why would you *not* want a weakref proxy back (on its own there isn't much use for that but as part of an object graph having serialization turn a weakref into a strong reference sounds like an anti-feature).
However, it looks like implementing __reduce__ is sufficient for my use case. Although the special-method-lookup-on-instance is still a nuisance.
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list