Fix bug in copy() by using copy.copy() instead of making assumptions

(it so happens that copy.copy() works fine for the base UserDict
type).  Also reindented the entire module to have 4-space indents.
This commit is contained in:
Guido van Rossum 1997-06-03 14:10:01 +00:00
parent bd40d7e69f
commit b94cd96977

View file

@ -14,14 +14,8 @@ class UserDict:
def __delitem__(self, key): del self.data[key]
def clear(self): return self.data.clear()
def copy(self):
if self.__class__ is UserDict:
new = UserDict()
new.dict = self.data.copy()
else:
new = self.__class__() # XXX assumption: constructor signature
for k, v in self.items():
new[k] = v
return new
import copy
return copy.copy(self)
def keys(self): return self.data.keys()
def items(self): return self.data.items()
def values(self): return self.data.values()