mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
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:
parent
bd40d7e69f
commit
b94cd96977
1 changed files with 25 additions and 31 deletions
|
@ -14,14 +14,8 @@ class UserDict:
|
||||||
def __delitem__(self, key): del self.data[key]
|
def __delitem__(self, key): del self.data[key]
|
||||||
def clear(self): return self.data.clear()
|
def clear(self): return self.data.clear()
|
||||||
def copy(self):
|
def copy(self):
|
||||||
if self.__class__ is UserDict:
|
import copy
|
||||||
new = UserDict()
|
return copy.copy(self)
|
||||||
new.dict = self.data.copy()
|
|
||||||
else:
|
|
||||||
new = self.__class__() # XXX assumption: constructor signature
|
|
||||||
for k, v in self.items():
|
|
||||||
new[k] = v
|
|
||||||
return new
|
|
||||||
def keys(self): return self.data.keys()
|
def keys(self): return self.data.keys()
|
||||||
def items(self): return self.data.items()
|
def items(self): return self.data.items()
|
||||||
def values(self): return self.data.values()
|
def values(self): return self.data.values()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue