]> granicus.if.org Git - python/commitdiff
Issue 11875: Keep OrderedDict's __reduce__ from temporarily mutating the object.
authorRaymond Hettinger <python@rcn.com>
Tue, 19 Apr 2011 16:48:39 +0000 (09:48 -0700)
committerRaymond Hettinger <python@rcn.com>
Tue, 19 Apr 2011 16:48:39 +0000 (09:48 -0700)
Lib/collections.py
Misc/NEWS

index 3c54690eb587b1ec6e307dae42b9fff6ea8e4b04..28a2abf44f8aada6743a09fb062431f94ff4e83b 100644 (file)
@@ -115,10 +115,9 @@ class OrderedDict(dict):
     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,)
index 51a0b672de844c38927afcc85b20a23f989a6a7b..63e8d728ea8a04fca91cf0abd075306958b4814c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -59,6 +59,9 @@ Library
   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.