SF patch #667730: More DictMixin

* Adds missing pop() methods to weakref.py
* Expands test suite to broaden coverage of objects with
  a mapping interface.

Contributed by Sebastien Keim.
This commit is contained in:
Raymond Hettinger 2003-03-09 07:05:43 +00:00
parent 42182ebaf6
commit 2c2d322884
6 changed files with 222 additions and 4 deletions

View file

@ -101,6 +101,18 @@ class WeakValueDictionary(UserDict.UserDict):
if o is not None:
return key, o
def pop(self, key, *args):
try:
o = self.data.pop(key)()
except KeyError:
if args:
return args[0]
raise
if o is None:
raise KeyError, key
else:
return o
def setdefault(self, key, default):
try:
wr = self.data[key]
@ -225,6 +237,9 @@ class WeakKeyDictionary(UserDict.UserDict):
if o is not None:
return o, value
def pop(self, key, *args):
return self.data.pop(ref(key), *args)
def setdefault(self, key, default):
return self.data.setdefault(ref(key, self._remove),default)