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

raymond.hettinger python-checkins at python.org
Tue Apr 19 20:15:46 CEST 2011


http://hg.python.org/cpython/rev/937385024601
changeset:   69448:937385024601
branch:      3.2
parent:      69439:d4bc42400692
parent:      69446:87440bf1994f
user:        Raymond Hettinger <python at rcn.com>
date:        Tue Apr 19 11:10:43 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
@@ -154,10 +154,9 @@
     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,)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -68,6 +68,9 @@
 
 - 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.
 

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


More information about the Python-checkins mailing list