[issue8738] cPickle dumps(tuple) != dumps(loads(dumps(tuple)))
Alexander Belopolsky
report at bugs.python.org
Thu Jul 15 07:22:55 CEST 2010
Alexander Belopolsky <belopolsky at users.sourceforge.net> 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: ( MARK
1: I INT 1
4: t TUPLE (MARK at 0)
5: . STOP
highest protocol among opcodes = 0
>>> t = 1,
>>> dis(dumps(t))
0: ( MARK
1: I INT 1
4: t TUPLE (MARK at 0)
5: p PUT 1
8: . STOP
highest protocol among opcodes = 0
This optimization is not available from python, of course so pickle.py behaves differently.
The remaining question is why this optimization was removed from 3.x.
----------
versions: +Python 3.2 -Python 2.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8738>
_______________________________________
More information about the Python-bugs-list
mailing list