]> granicus.if.org Git - python/commitdiff
Issue #15535: Fix pickling of named tuples.
authorGeorg Brandl <georg@python.org>
Sun, 12 May 2013 09:09:11 +0000 (11:09 +0200)
committerGeorg Brandl <georg@python.org>
Sun, 12 May 2013 09:09:11 +0000 (11:09 +0200)
Lib/collections.py
Lib/test/test_collections.py
Misc/NEWS

index eb2024352de18a7d1f483c91007d3d2e9e6301e0..33aedd973a50edb3616018a3fda6a1d89acc6c7c 100644 (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}
 '''
 
index b2a5f052604d92c3864abd2652f6f31850372f41..c18256b788d31e43cb00e5adfe3723df2b5b76e2 100644 (file)
@@ -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)
index e3e203f9b520b994bdd559447b293af5d153923e..a062175107ccc21ca9a583ebabb978d3a8c25edb 100644 (file)
--- 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?
 ===========================