]> granicus.if.org Git - python/commitdiff
WeakKeyDictionary.has_key(): If the key being tested is not weakly
authorFred Drake <fdrake@acm.org>
Tue, 6 Nov 2001 16:36:53 +0000 (16:36 +0000)
committerFred Drake <fdrake@acm.org>
Tue, 6 Nov 2001 16:36:53 +0000 (16:36 +0000)
referencable (weakref.ref() raises TypeError), return 0 instead of
propogating the TypeError.
This closes SF bug #478536; bugfix candidate.

Lib/weakref.py

index 39ec33049d2c08785afdb62ec62b399ac6d74777..967458d989dc115e68756037f711b7e223a63110 100644 (file)
@@ -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 = []