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.
This commit is contained in:
Fred Drake 2001-11-06 16:36:53 +00:00
parent 5cc6d6e58e
commit 3bae7ddf8e
1 changed files with 5 additions and 1 deletions

View 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 = []