From: Raymond Hettinger Date: Tue, 19 Apr 2011 17:21:27 +0000 (-0700) Subject: Issue 11875: Keep OrderedDict's __reduce__ from temporarily mutating the object. X-Git-Tag: v3.2.1b1~102^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=019a97c77cc750d104adcc53ca4b84e29a069317;p=python Issue 11875: Keep OrderedDict's __reduce__ from temporarily mutating the object. --- diff --git a/Lib/collections.py b/Lib/collections.py index cde734debd..a1f789082b 100644 --- a/Lib/collections.py +++ b/Lib/collections.py @@ -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,) diff --git a/Misc/NEWS b/Misc/NEWS index fa8f039b82..1885fb73cf 100644 --- 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.