]> granicus.if.org Git - python/commitdiff
copy(): Make sure the copy of a derived class cannot share the data of the
authorFred Drake <fdrake@acm.org>
Mon, 5 Nov 2001 17:40:48 +0000 (17:40 +0000)
committerFred Drake <fdrake@acm.org>
Mon, 5 Nov 2001 17:40:48 +0000 (17:40 +0000)
original by replacing self.data temporarily, then using the update() method
on the new mapping object to populate it.
This closes SF bug #476616.

Lib/UserDict.py

index b806ac1603fb1a84a125c983040d293d081f6336..b78860fc9e2f0416112aec98d3bb1136e873b1fe 100644 (file)
@@ -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()