[issue14577] pickling uses __class__ so you can't pickle proxy/mock objects that pretend to be other objects
Nick Coghlan
report at bugs.python.org
Sat Apr 14 13:48:59 CEST 2012
Nick Coghlan <ncoghlan at gmail.com> added the comment:
Some additional thoughts for anyone else that comes across this issue.
Consider the case of a weakref proxy (the only proxy type in the stdlib): for that, you never want to serialise the proxy, you want to serialise the original object.
To correctly serialise a proxy object, you have to somehow ensure:
- the proxy gets serialised
- the target gets serialised
- the two get hooked up again at the far end
Now consider what happens if you have *two* proxies both pointing at the same target: how do you ensure that, when deserialised, both proxies still share a target?
In the general case, you can't - so pickle doesn't even try. Instead, serialising a proxy serialises the original object - if you want to do something else, you need to decide for yourself how to recreate the cross-references correctly on deserialisation.
----------
nosy: +ncoghlan
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14577>
_______________________________________
More information about the Python-bugs-list
mailing list