mirror of
https://github.com/python/cpython.git
synced 2025-08-24 18:55:00 +00:00
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:
parent
42182ebaf6
commit
2c2d322884
6 changed files with 222 additions and 4 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue