Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 98c850a

Browse files
committed
Issue 11875: Keep OrderedDict's __reduce__ from temporarily mutating the object.
2 parents 64e564b + 35b873a commit 98c850a

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

Lib/collections/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,9 @@ def move_to_end(self, key, last=True):
155155
def __reduce__(self):
156156
'Return state information for pickling'
157157
items = [[k, self[k]] for k in self]
158-
tmp = self.__map, self.__root, self.__hardroot
159-
del self.__map, self.__root, self.__hardroot
160158
inst_dict = vars(self).copy()
161-
self.__map, self.__root, self.__hardroot = tmp
159+
for k in vars(self.__class__()):
160+
inst_dict.pop(k, None)
162161
if inst_dict:
163162
return (self.__class__, (items,), inst_dict)
164163
return self.__class__, (items,)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ Library
121121

122122
- Issue #11852: Add missing imports and update tests.
123123

124+
- Issue #11875: collections.OrderedDict's __reduce__ was temporarily
125+
mutating the object instead of just working on a copy.
126+
124127
- Issue #11467: Fix urlparse behavior when handling urls which contains scheme
125128
specific part only digits. Patch by Santoso Wijaya.
126129

0 commit comments

Comments
 (0)