summaryrefslogtreecommitdiff
path: root/apscheduler
diff options
context:
space:
mode:
authorAlex Grönholm <alex.gronholm@nextday.fi>2014-10-10 00:40:47 +0300
committerAlex Grönholm <alex.gronholm@nextday.fi>2014-10-20 13:21:49 +0300
commit235fd14a70d855f5eccb167feccb573494883548 (patch)
tree37024088284b53905272314fb01e8314eecd3936 /apscheduler
parent740b66f8c0a43a501438092ca0b3fba326c2491d (diff)
downloadapscheduler-235fd14a70d855f5eccb167feccb573494883548.tar.gz
Modified get_callable_name() to work with a wider variety of callables
Diffstat (limited to 'apscheduler')
-rw-r--r--apscheduler/util.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/apscheduler/util.py b/apscheduler/util.py
index 9396593..988f942 100644
--- a/apscheduler/util.py
+++ b/apscheduler/util.py
@@ -194,20 +194,26 @@ def get_callable_name(func):
:rtype: str
"""
- f_self = getattr(func, '__self__', None) or getattr(func, 'im_self', None)
+ # the easy case (on Python 3.3+)
+ if hasattr(func, '__qualname__'):
+ return func.__qualname__
+ # class methods, bound and unbound methods
+ f_self = getattr(func, '__self__', None) or getattr(func, 'im_self', None)
if f_self and hasattr(func, '__name__'):
- if isinstance(f_self, type):
- # class method
- clsname = getattr(f_self, '__qualname__', None) or f_self.__name__
- return '%s.%s' % (clsname, func.__name__)
- # bound method
- return '%s.%s' % (f_self.__class__.__name__, func.__name__)
+ f_class = f_self if isinstance(f_self, type) else f_self.__class__
+ else:
+ f_class = getattr(func, 'im_class', None)
+ if f_class and hasattr(func, '__name__'):
+ return '%s.%s' % (f_class.__name__, func.__name__)
+
+ # class or class instance
if hasattr(func, '__call__'):
+ # class
if hasattr(func, '__name__'):
- # function, unbound method or a class with a __call__ method
return func.__name__
+
# instance of a class with a __call__ method
return func.__class__.__name__