From: Fred Drake Date: Thu, 6 Sep 2001 14:51:01 +0000 (+0000) Subject: Add __delitem__() support for WeakKeyDictionary. X-Git-Tag: v2.2a3~49 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b663a2ccbdd9bbd9a13f0cea743af709c53ec0c1;p=python Add __delitem__() support for WeakKeyDictionary. This closes SF bug #458860. --- diff --git a/Lib/weakref.py b/Lib/weakref.py index 1d21e79886..c71d04b853 100644 --- a/Lib/weakref.py +++ b/Lib/weakref.py @@ -146,6 +146,13 @@ class WeakKeyDictionary(UserDict.UserDict): del data[k] self._remove = remove + def __delitem__(self, key): + for ref in self.data.iterkeys(): + o = ref() + if o == key: + del self.data[ref] + return + def __getitem__(self, key): return self.data[ref(key)]