[Python-Dev] pickle and copy discrepancy
storchaka at gmail.com
Wed Mar 2 04:15:39 EST 2016
On 01.03.16 18:34, Ethan Furman wrote:
> On 03/01/2016 03:14 AM, Serhiy Storchaka wrote:
>> The difference is that the copy module sets object's state before adding
>> items and key-value pairs, but the pickle module sets object's state
>> after adding items and key-value pairs. If append() or __setitem__()
>> depend on the state of the object, the pickling is incompatible with the
> Aren't there tests to ensure the unpickled/copied object are identical
> to the original object?
We have no pickle/copy tests for every class. And of course we can't
test third-party classes. But even if write tests and they will fail,
what to do? The problem is that for some classes pickle and copy
contradict. An implementation that works with copy doesn't work with
pickle or vice verse.
> Under which circumstances would they be different?
If append() or __setitem__() depend on the state or change the state.
See examples in issue1099746 and issue10131.
More information about the Python-Dev