summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2001-06-18 01:09:41 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2001-06-18 01:09:41 (GMT)
commitf3b30747d660f3cecfbb5a8136d5dc30770c0882 (patch)
treec3a1b37997da088add929d3fac6a4fbf67183ad8
parentfa9e273442c1970cc5910b3f5920a8dcdf4f5fc1 (diff)
downloadcpython-f3b30747d660f3cecfbb5a8136d5dc30770c0882.zip
cpython-f3b30747d660f3cecfbb5a8136d5dc30770c0882.tar.gz
cpython-f3b30747d660f3cecfbb5a8136d5dc30770c0882.tar.bz2
Patch #413171: Implement get, setdefault, update in terms of
has_key, __getitem__, and __setitem__.
-rw-r--r--Lib/UserDict.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/Lib/UserDict.py b/Lib/UserDict.py
index 204ca15..fbd601a 100644
--- a/Lib/UserDict.py
+++ b/Lib/UserDict.py
@@ -34,13 +34,15 @@ class UserDict:
self.data.update(dict)
else:
for k, v in dict.items():
- self.data[k] = v
+ self[k] = v
def get(self, key, failobj=None):
- return self.data.get(key, failobj)
+ if not self.has_key(key):
+ return failobj
+ return self[key]
def setdefault(self, key, failobj=None):
- if not self.data.has_key(key):
- self.data[key] = failobj
- return self.data[key]
+ if not self.has_key(key):
+ self[key] = failobj
+ return self[key]
def popitem(self):
return self.data.popitem()
def __contains__(self, key):