diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2001-06-18 01:09:41 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2001-06-18 01:09:41 (GMT) |
commit | f3b30747d660f3cecfbb5a8136d5dc30770c0882 (patch) | |
tree | c3a1b37997da088add929d3fac6a4fbf67183ad8 /Lib | |
parent | fa9e273442c1970cc5910b3f5920a8dcdf4f5fc1 (diff) | |
download | cpython-f3b30747d660f3cecfbb5a8136d5dc30770c0882.zip cpython-f3b30747d660f3cecfbb5a8136d5dc30770c0882.tar.gz cpython-f3b30747d660f3cecfbb5a8136d5dc30770c0882.tar.bz2 |
Patch #413171: Implement get, setdefault, update in terms of
has_key, __getitem__, and __setitem__.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/UserDict.py | 12 |
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): |