]> granicus.if.org Git - python/commitdiff
Issue #15535: Fix pickling of named tuples.
authorRaymond Hettinger <python@rcn.com>
Fri, 3 May 2013 09:24:15 +0000 (02:24 -0700)
committerRaymond Hettinger <python@rcn.com>
Fri, 3 May 2013 09:24:15 +0000 (02:24 -0700)
Lib/collections/__init__.py
Lib/test/test_collections.py
Misc/ACKS
Misc/NEWS

index 707c53b3e15ff97d90baa3642b1913f2194b97b5..9f55a3e7a373d609ed231ac77902bf55a626288d 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 8850e8bc136893139ae200addbeb5f7a1783e722..af27d22b4ed4b264dac7028aa45a7af8c190a32b 100644 (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)
index 3b0630abb149f9a06bb32aa186e0208d4bb7c5b0..6a0d16fb8c372dacd041cb9428dafcc5aa36bdd5 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -811,6 +811,7 @@ Trent Mick
 Jason Michalski
 Franck Michea
 Tom Middleton
+Thomas Miedema
 Stan Mihai
 Stefan Mihaila
 Aristotelis Mikropoulos
index 465ca10ff014d477876c9d37c16bfc5312fd876f..db0c594d5fd2f4ed11600f884c54bdbc749c67ec 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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.