Issue #15535: Fix pickling of named tuples.

This commit is contained in:
Raymond Hettinger 2013-05-03 02:24:15 -07:00
parent 8e596a765c
commit b98dcc1f53
4 changed files with 9 additions and 0 deletions

View File

@ -281,6 +281,10 @@ class {typename}(tuple):
'Return self as a plain tuple. Used by copy and pickle.'
return tuple(self)
def __getstate__(self):
'Exclude the OrderedDict from pickling'
return None
{field_defs}
'''

View File

@ -273,6 +273,7 @@ class TestNamedTuple(unittest.TestCase):
q = loads(dumps(p, protocol))
self.assertEqual(p, q)
self.assertEqual(p._fields, q._fields)
self.assertNotIn(b'OrderedDict', dumps(p, protocol))
def test_copy(self):
p = TestNT(x=10, y=20, z=30)

View File

@ -811,6 +811,7 @@ Trent Mick
Jason Michalski
Franck Michea
Tom Middleton
Thomas Miedema
Stan Mihai
Stefan Mihaila
Aristotelis Mikropoulos

View File

@ -47,6 +47,9 @@ Library
- Issue #17802: Fix an UnboundLocalError in html.parser. Initial tests by
Thomas Barlow.
- Issue #15535: Fix namedtuple pickles which were picking up the OrderedDict
instead of just the underlying tuple.
- Issue #17192: Restore the patch for Issue #11729 which was ommitted in
3.3.1 when updating the bundled version of libffi used by ctypes. Update
many libffi files that were missed in 3.3.1's update to libffi-3.0.13.