]> 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 17:21:27 +0000 (10:21 -0700)
committerRaymond Hettinger <python@rcn.com>
Tue, 19 Apr 2011 17:21:27 +0000 (10:21 -0700)
Lib/collections.py
Misc/NEWS

index cde734debd9384d131098eefd47ae5c0e42fde65..a1f789082b5e78e4cb27b000578529ddad5dbf2a 100644 (file)
@@ -154,10 +154,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, self.__hardroot
-        del self.__map, self.__root, self.__hardroot
         inst_dict = vars(self).copy()
-        self.__map, self.__root, self.__hardroot = tmp
+        for k in vars(self.__class__()):
+            inst_dict.pop(k, None)
         if inst_dict:
             return (self.__class__, (items,), inst_dict)
         return self.__class__, (items,)
index fa8f039b82c30d36bef9cec1f85418ea3ab99e37..1885fb73cf9bb1258b89c870804467d942a93f24 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -62,6 +62,9 @@ Library
 
 - Issue #11852: Add missing imports and update tests.
 
+- Issue #11875: collections.OrderedDict's __reduce__ was temporarily
+  mutating the object instead of just working on a copy.
+
 - Issue #11467: Fix urlparse behavior when handling urls which contains scheme
   specific part only digits. Patch by Santoso Wijaya.