From 2c2d322884ee72077a256ec3cd0aa9ce3580eedc Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sun, 9 Mar 2003 07:05:43 +0000 Subject: 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. --- Lib/weakref.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'Lib/weakref.py') diff --git a/Lib/weakref.py b/Lib/weakref.py index 6153bd966d..838ff5ef7a 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) -- cgit v1.2.1