From: Fred Drake Date: Tue, 6 Nov 2001 16:36:53 +0000 (+0000) Subject: WeakKeyDictionary.has_key(): If the key being tested is not weakly X-Git-Tag: v2.2.1c1~842 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3bae7ddf8e63889b185235f85a6695bc05d59059;p=python WeakKeyDictionary.has_key(): If the key being tested is not weakly referencable (weakref.ref() raises TypeError), return 0 instead of propogating the TypeError. This closes SF bug #478536; bugfix candidate. --- diff --git a/Lib/weakref.py b/Lib/weakref.py index 39ec33049d..967458d989 100644 --- a/Lib/weakref.py +++ b/Lib/weakref.py @@ -179,7 +179,11 @@ class WeakKeyDictionary(UserDict.UserDict): return self.data.get(ref(key),default) def has_key(self, key): - return self.data.has_key(ref(key)) + try: + wr = ref(key) + except TypeError: + return 0 + return self.data.has_key(wr) def items(self): L = []