diff options
author | Fred Drake <fdrake@acm.org> | 2001-11-05 17:40:48 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2001-11-05 17:40:48 (GMT) |
commit | 3ce5af70e352b3a8fbea8e3f27464b6ca2d66ebd (patch) | |
tree | 48a269d52db6299822267b674e5856f6d55cddbd | |
parent | 9c2b514014da667e430b9118317876eb1f5e3367 (diff) | |
download | cpython-3ce5af70e352b3a8fbea8e3f27464b6ca2d66ebd.zip cpython-3ce5af70e352b3a8fbea8e3f27464b6ca2d66ebd.tar.gz cpython-3ce5af70e352b3a8fbea8e3f27464b6ca2d66ebd.tar.bz2 |
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.
-rw-r--r-- | Lib/UserDict.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/UserDict.py b/Lib/UserDict.py index b806ac1..b78860f 100644 --- a/Lib/UserDict.py +++ b/Lib/UserDict.py @@ -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() |