Alexander Belopolsky added the comment:
I am speculating here while Alexandre probably knows the answer. The skip PUT
on unreferenced objects optimization was probably removed because doing so
makes _pickle module behave more like pickle and because pickletools now has
optimize method which
Alexander Belopolsky added the comment:
OK, the 2.7 behavior is explainable and correct. cPickle checks the reference
count and does not generate PUT for objects that don't have references:
>>> from pickletools import dis
>>> from cPickle import dumps
>>> dis(dumps(tuple([1])))
0: (MA
Alexander Belopolsky added the comment:
There seems to be a bug somewhere in 2.x cPickle. Here is a somewhat simpler
way to demonstrate the bug: the following code
from pickletools import dis
import cPickle
t = 1L, # use long for easy 3.x comparison
s1 = cPickle.dumps(t)
s2 = cPickle.dumps(cP
Antoine Pitrou added the comment:
I don't think you can expect serialized results to always be equal. It can
depend on specifics of the internal algorithm, such as optimizations or dict
iteration order.
--
nosy: +alexandre.vassalotti, pitrou
priority: normal -> low
versions: +Python 2
New submission from Alberto Planas DomÃnguez :
Sometimes, when I use cPickle to serialize tuples of strings, I get different
dumps() result for the same tuple:
import cPickle
t = ('', 'JOHN')
s1 = cPickle.dumps(t)
s2 = cPickle.dumps(cPickle.loads(cPickle.dumps(t)))
assert s1 == s2 # Asserti