From f3b30747d660f3cecfbb5a8136d5dc30770c0882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Mon, 18 Jun 2001 01:09:41 +0000 Subject: Patch #413171: Implement get, setdefault, update in terms of has_key, __getitem__, and __setitem__. --- Lib/UserDict.py | 12 +++++++----- 1 file 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): -- cgit v0.12