mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
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.
This commit is contained in:
parent
9c2b514014
commit
3ce5af70e3
1 changed files with 8 additions and 1 deletions
|
@ -19,7 +19,14 @@ class UserDict:
|
|||
if self.__class__ is UserDict:
|
||||
return UserDict(self.data)
|
||||
import copy
|
||||
return copy.copy(self)
|
||||
data = self.data
|
||||
try:
|
||||
self.data = {}
|
||||
c = copy.copy(self)
|
||||
finally:
|
||||
self.data = data
|
||||
c.update(self)
|
||||
return c
|
||||
def keys(self): return self.data.keys()
|
||||
def items(self): return self.data.items()
|
||||
def iteritems(self): return self.data.iteritems()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue