Fix "target" attribute calls via six

master
Aniket21mathur 5 years ago committed by James Cameron
parent ed46c219a9
commit 490a602367

@ -12,7 +12,7 @@ WEAKREF_TYPES = (weakref.ReferenceType, saferef.BoundMethodWeakref)
def _make_id(target):
if hasattr(target, 'im_func'):
if hasattr(target, 'im_func') or hasattr(target, '__func__'):
return (id(im_self(target)), id(im_func(target)))
return id(target)

@ -21,13 +21,19 @@ def safeRef(target, onDelete=None):
goes out of scope with the reference object, (either a
weakref or a BoundMethodWeakref) as argument.
"""
if hasattr(target, 'im_self'):
if hasattr(target, 'im_self') or hasattr(target, '__self__'):
if im_self(target) is not None:
# Turn a bound method into a BoundMethodWeakref instance.
# Keep track of these instances for lookup by disconnect().
assert hasattr(target, 'im_func'), \
"safeRef target %r has im_self, but no im_func, " \
"don't know how to create reference" % (target,)
if six.PY2:
assert hasattr(target, 'im_func'), \
"safeRef target %r has im_self, but no im_func, " \
"don't know how to create reference" % (target,)
else:
assert hasattr(target, '__func__'), \
"safeRef target %r has __self__, but no __func__, " \
"don't know how to create reference" % (target,)
reference = get_bound_method_weakref(
target=target,
onDelete=onDelete

Loading…
Cancel
Save