[issue13503] improved efficiency of bytearray pickling by using bytes type instead of str

Antoine Pitrou report at bugs.python.org
Wed Nov 30 03:07:08 CET 2011


Antoine Pitrou <pitrou at free.fr> added the comment:

Since it's a performance improvement, it's Python 3.3-only.

The patch looks ok but there's an unrelated issue. If I first pickle a bytearray under 3.3 using protocol 2:

>>> b = bytearray(b'xyz')
>>> pickle.dumps(b, protocol=2)
b'\x80\x02c__builtin__\nbytearray\nq\x00c__builtin__\nbytes\nq\x01]q\x02(KxKyKze\x85q\x03Rq\x04\x85q\x05Rq\x06.'

and then unpickle it under 2.7, I get:

>>> pickle.loads(b'\x80\x02c__builtin__\nbytearray\nq\x00c__builtin__\nbytes\nq\x01]q\x02(KxKyKze\x85q\x03Rq\x04\x85q\x05Rq\x06.')
bytearray(b'[120, 121, 122]')

... which is wrong. It seems pickling bytes objects with protocol 2 and unpickling them with Python 2.x is broken.

----------
versions:  -Python 2.7, Python 3.1, Python 3.2, Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13503>
_______________________________________


More information about the Python-bugs-list mailing list