diff options
author | Raymond Hettinger <python@rcn.com> | 2003-03-09 07:05:43 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2003-03-09 07:05:43 (GMT) |
commit | 2c2d322884ee72077a256ec3cd0aa9ce3580eedc (patch) | |
tree | d64fac31dcecd48ed44aceb9d5fb6d8dc415e95f /Lib/weakref.py | |
parent | 42182ebaf6387371c238d2a3484e7f1e085c9d1c (diff) | |
download | cpython-2c2d322884ee72077a256ec3cd0aa9ce3580eedc.zip cpython-2c2d322884ee72077a256ec3cd0aa9ce3580eedc.tar.gz cpython-2c2d322884ee72077a256ec3cd0aa9ce3580eedc.tar.bz2 |
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.
Diffstat (limited to 'Lib/weakref.py')
-rw-r--r-- | Lib/weakref.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/weakref.py b/Lib/weakref.py index 6153bd9..838ff5e 100644 --- a/Lib/weakref.py +++ b/Lib/weakref.py @@ -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) |