summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-06-03 14:10:01 +0000
committerGuido van Rossum <guido@python.org>1997-06-03 14:10:01 +0000
commitb94cd96977ac4d3c2c335ff7d72033d818d59d84 (patch)
treeae63195f2545b455e62041f036293c5b8c1fa2ff
parentbd40d7e69ffd53f36a315605fc849bb12ae1f55f (diff)
downloadcpython-git-b94cd96977ac4d3c2c335ff7d72033d818d59d84.tar.gz
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.
-rw-r--r--Lib/UserDict.py56
1 files changed, 25 insertions, 31 deletions
diff --git a/Lib/UserDict.py b/Lib/UserDict.py
index 3ee4743815..2f4f541942 100644
--- a/Lib/UserDict.py
+++ b/Lib/UserDict.py
@@ -1,34 +1,28 @@
# A more or less complete user-defined wrapper around dictionary objects
class UserDict:
- def __init__(self): self.data = {}
- def __repr__(self): return repr(self.data)
- def __cmp__(self, dict):
- if type(dict) == type(self.data):
- return cmp(self.data, dict)
- else:
- return cmp(self.data, dict.data)
- def __len__(self): return len(self.data)
- def __getitem__(self, key): return self.data[key]
- def __setitem__(self, key, item): self.data[key] = item
- 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
- def keys(self): return self.data.keys()
- def items(self): return self.data.items()
- def values(self): return self.data.values()
- def has_key(self, key): return self.data.has_key(key)
- def update(self, other):
- if type(other) is type(self.data):
- self.data.update(other)
- else:
- for k, v in other.items():
- self.data[k] = v
+ def __init__(self): self.data = {}
+ def __repr__(self): return repr(self.data)
+ def __cmp__(self, dict):
+ if type(dict) == type(self.data):
+ return cmp(self.data, dict)
+ else:
+ return cmp(self.data, dict.data)
+ def __len__(self): return len(self.data)
+ def __getitem__(self, key): return self.data[key]
+ def __setitem__(self, key, item): self.data[key] = item
+ def __delitem__(self, key): del self.data[key]
+ def clear(self): return self.data.clear()
+ def copy(self):
+ 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()
+ def has_key(self, key): return self.data.has_key(key)
+ def update(self, other):
+ if type(other) is type(self.data):
+ self.data.update(other)
+ else:
+ for k, v in other.items():
+ self.data[k] = v