[Python-checkins] cpython (2.7): Issue 11875: Keep OrderedDict's __reduce__ from temporarily mutating the object.

raymond.hettinger python-checkins at python.org
Tue Apr 19 18:54:59 CEST 2011


http://hg.python.org/cpython/rev/3150b6939731
changeset:   69441:3150b6939731
branch:      2.7
parent:      69438:18d29c790bd0
user:        Raymond Hettinger <python at rcn.com>
date:        Tue Apr 19 09:48:39 2011 -0700
summary:
  Issue 11875: Keep OrderedDict's __reduce__ from temporarily mutating the object.

files:
  Lib/collections.py |  5 ++---
  Misc/NEWS          |  3 +++
  2 files changed, 5 insertions(+), 3 deletions(-)


diff --git a/Lib/collections.py b/Lib/collections.py
--- a/Lib/collections.py
+++ b/Lib/collections.py
@@ -115,10 +115,9 @@
     def __reduce__(self):
         'Return state information for pickling'
         items = [[k, self[k]] for k in self]
-        tmp = self.__map, self.__root
-        del self.__map, self.__root
         inst_dict = vars(self).copy()
-        self.__map, self.__root = tmp
+        for k in vars(OrderedDict()):
+            inst_dict.pop(k, None)
         if inst_dict:
             return (self.__class__, (items,), inst_dict)
         return self.__class__, (items,)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -59,6 +59,9 @@
   Py_AddPendingCall() for the first signal to fix a deadlock on reentrant or
   parallel calls. PyErr_SetInterrupt() writes also into the wake up file.
 
+- Issue #11875: collections.OrderedDict's __reduce__ was temporarily
+  mutating the object instead of just working on a copy.
+
 - Issue #11442: Add a charset parameter to the Content-type in SimpleHTTPServer
   to avoid XSS attacks.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list