]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #15535: Fix regression in pickling of named tuples.
authorRaymond Hettinger <python@rcn.com>
Fri, 3 May 2013 07:59:20 +0000 (00:59 -0700)
committerRaymond Hettinger <python@rcn.com>
Fri, 3 May 2013 07:59:20 +0000 (00:59 -0700)
Doc/library/collections.rst
Lib/collections.py
Lib/test/test_collections.py
Misc/NEWS

index 50115ab68579979d199a39f3b042e3852a67b3b1..ab290e79f3588fc06c0729ce00026f12f111dade 100644 (file)
@@ -628,9 +628,7 @@ Example:
            'Return a new OrderedDict which maps field names to their values'
            return OrderedDict(zip(self._fields, self))
    <BLANKLINE>
-      __dict__ = property(_asdict)
-   <BLANKLINE>
-      def _replace(_self, **kwds):
+       def _replace(_self, **kwds):
            'Return a new Point object replacing specified fields with new values'
            result = _self._make(map(kwds.pop, ('x', 'y'), _self))
            if kwds:
index faf677b7bf722bf32a920ba3f4a06cbfd8919113..af32e448a9ce923c40a0692faf354465b5cdb7e7 100644 (file)
@@ -259,8 +259,6 @@ class {typename}(tuple):
         'Return a new OrderedDict which maps field names to their values'
         return OrderedDict(zip(self._fields, self))
 
-    __dict__ = property(_asdict)
-
     def _replace(_self, **kwds):
         'Return a new {typename} object replacing specified fields with new values'
         result = _self._make(map(kwds.pop, {field_names!r}, _self))
index 313f81ff65670b3ed7fe51bc1b902cb172b6fe99..8bdeb3d8f1f9b883fa5597fe084a29cc37ee4f82 100644 (file)
@@ -78,12 +78,12 @@ class TestNamedTuple(unittest.TestCase):
         self.assertRaises(TypeError, eval, 'Point(XXX=1, y=2)', locals())   # wrong keyword argument
         self.assertRaises(TypeError, eval, 'Point(x=1)', locals())          # missing keyword argument
         self.assertEqual(repr(p), 'Point(x=11, y=22)')
+        self.assertNotIn('__dict__', dir(p))                              # verify instance has no dict
         self.assertNotIn('__weakref__', dir(p))
         self.assertEqual(p, Point._make([11, 22]))                          # test _make classmethod
         self.assertEqual(p._fields, ('x', 'y'))                             # test _fields attribute
         self.assertEqual(p._replace(x=1), (1, 22))                          # test _replace method
         self.assertEqual(p._asdict(), dict(x=11, y=22))                     # test _asdict method
-        self.assertEqual(vars(p), p._asdict())                              # verify that vars() works
 
         try:
             p._replace(x=1, error=2)
index b61bf230d18e5dc21f9212ee0b7226521f6b51d6..625d300e84279c20d0777f01c355dc70508f3842 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -17,6 +17,9 @@ Build
 Core and Builtins
 -----------------
 
+- Issue #15535: Fixed regression in the pickling of named tuples by 
+  removing the __dict__ property introduced in 2.7.4.
+
 - Issue #17857: Prevent build failures with pre-3.5.0 versions of sqlite3,
   such as was shipped with Centos 5 and Mac OS X 10.4.