From 490a602367debdddeebfce8e20eb5ee2301237f1 Mon Sep 17 00:00:00 2001 From: Aniket21mathur Date: Sat, 13 Jul 2019 18:15:02 +0530 Subject: [PATCH] Fix "target" attribute calls via six --- src/sugar3/dispatch/dispatcher.py | 2 +- src/sugar3/dispatch/saferef.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/sugar3/dispatch/dispatcher.py b/src/sugar3/dispatch/dispatcher.py index 4b437a3a..222fc7f5 100644 --- a/src/sugar3/dispatch/dispatcher.py +++ b/src/sugar3/dispatch/dispatcher.py @@ -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) diff --git a/src/sugar3/dispatch/saferef.py b/src/sugar3/dispatch/saferef.py index 405c06d5..b3f8d769 100644 --- a/src/sugar3/dispatch/saferef.py +++ b/src/sugar3/dispatch/saferef.py @@ -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