py3: fix WeakMethod.is_dead(). Now touchtracer works!

This commit is contained in:
Mathieu Virbel 2012-12-29 02:23:49 +01:00 committed by Dusty Phillips
parent a8b7abd72c
commit 2e6766fe2e
1 changed files with 8 additions and 2 deletions

View File

@ -20,6 +20,8 @@ if sys.version > '3':
'''Implementation of weakref for function and bounded method. '''Implementation of weakref for function and bounded method.
''' '''
def __init__(self, method): def __init__(self, method):
self.method = None
self.method_name = None
try: try:
if method.__self__ is not None: if method.__self__ is not None:
self.method_name = method.__func__.__name__ self.method_name = method.__func__.__name__
@ -28,8 +30,8 @@ if sys.version > '3':
self.method = method self.method = method
self.proxy = None self.proxy = None
except AttributeError: except AttributeError:
self.proxy = None
self.method = method self.method = method
self.proxy = None
def __call__(self): def __call__(self):
'''Return a new bound-method like the original, or the '''Return a new bound-method like the original, or the
@ -45,7 +47,11 @@ if sys.version > '3':
'''Returns True if the referenced callable was a bound method and '''Returns True if the referenced callable was a bound method and
the instance no longer exists. Otherwise, return False. the instance no longer exists. Otherwise, return False.
''' '''
return self.proxy is not None and bool(dir(self.proxy)) return self.proxy is not None and not bool(dir(self.proxy))
def __repr__(self):
return '<WeakMethod proxy={} method={} method_name={}>'.format(
self.proxy, self.method, self.method_name)
else: else: