Issue 11875: Keep OrderedDict's __reduce__ from temporarily mutating the object.

This commit is contained in:
Raymond Hettinger 2011-04-19 10:05:03 -07:00
parent 2876a8c272
commit d08a2c2576
2 changed files with 5 additions and 3 deletions

View 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,)