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

Skip to content

Commit 3ce5af7

Browse files
committed
copy(): Make sure the copy of a derived class cannot share the data of the
original by replacing self.data temporarily, then using the update() method on the new mapping object to populate it. This closes SF bug #476616.
1 parent 9c2b514 commit 3ce5af7

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

Lib/UserDict.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ def copy(self):
1919
if self.__class__ is UserDict:
2020
return UserDict(self.data)
2121
import copy
22-
return copy.copy(self)
22+
data = self.data
23+
try:
24+
self.data = {}
25+
c = copy.copy(self)
26+
finally:
27+
self.data = data
28+
c.update(self)
29+
return c
2330
def keys(self): return self.data.keys()
2431
def items(self): return self.data.items()
2532
def iteritems(self): return self.data.iteritems()

0 commit comments

Comments
 (0)