[New-bugs-announce] [issue15535] Fix pickling of named tuples in 2.7.3
report at bugs.python.org
Thu Aug 2 15:44:46 CEST 2012
New submission from Thomas Miedema:
Pickling a namedtuple Point(x=10, y=20, z=30) in Python 2.7.2 with protocol level 0 would result in something like the following output:
In Python 2.7.3, the same namedtuple dumps to:
Note the OrderedDictionary at the end. All data, the field names and the values, are duplicated, which can result in very large pickled files when using nested namedtuples.
Loading both dumps with CPython 2.7.3 works. This is why this bug was not noticed any earlier. Loading the second dump with CPython or pypy 2.7.2 does not work however. CPython 2.7.3 broke forward compatibility.
Attached is a patch with a fix. The patch makes pickled namedtuples forward compatibile with 2.7.2. This patch does not break backward compability with 2.7.3, since the extra OrderedDict data contained the same information as the tuple.
components: Library (Lib)
nosy: rhettinger, thomie
title: Fix pickling of named tuples in 2.7.3
versions: Python 2.7
Added file: http://bugs.python.org/file26662/namedtuple_pickle_fix.patch
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce