From: Georg Brandl Date: Sun, 12 May 2013 09:09:11 +0000 (+0200) Subject: Issue #15535: Fix pickling of named tuples. X-Git-Tag: v3.2.5~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ce654f48aac8c060ee3188f597e4fb78b2839abb;p=thirdparty%2FPython%2Fcpython.git Issue #15535: Fix pickling of named tuples. --- diff --git a/Lib/collections.py b/Lib/collections.py index eb2024352de1..33aedd973a50 100644 --- a/Lib/collections.py +++ b/Lib/collections.py @@ -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} ''' diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index b2a5f052604d..c18256b788d3 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -272,6 +272,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) diff --git a/Misc/NEWS b/Misc/NEWS index e3e203f9b520..a062175107cc 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -16,6 +16,9 @@ Library - Issue #17666: Fix reading gzip files with an extra field. +- Issue #15535: Fix namedtuple pickles which were picking up the OrderedDict + instead of just the underlying tuple. + What's New in Python 3.2.4? ===========================