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

index fb9464fa87eb4bed72aa61d6b00497b0900f17da..9381f516763e44607e40b50f3ece244ba8b82393 100644 (file)
@@ -101,10 +101,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.__in_repr
-        del self.__map, self.__root, self.__in_repr
         inst_dict = vars(self).copy()
-        self.__map, self.__root, self.__in_repr = 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 c424e1eb94bea9ccb96ea2b959b900bb6dd80407..7e95d80c13f256a4122144242d0db2579ca8b383 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -58,6 +58,9 @@ Library
 - Issue #11467: Fix urlparse behavior when handling urls which contains scheme
   specific part only digits. Patch by Santoso Wijaya.
 
+- Issue #11875: collections.OrderedDict's __reduce__ was temporarily
+  mutating the object instead of just working on a copy.
+
 - collections.Counter().copy() now works correctly for subclasses.
 
 - Issue #11474: Fix the bug with url2pathname() handling of '/C|/' on Windows.