Guest User

Untitled

a guest
Jan 16th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. def get_callable_name(func):
  2. if hasattr(func, '__qualname__'):
  3. return func.__qualname__
  4.  
  5. # get func's class
  6. f_self = getattr(func, '__self__', None) or getattr(func, 'im_self', None)
  7. if f_self and hasattr(func, '__name__'):
  8. # bound method class
  9. f_class = f_self if isinstance(f_self, type) else f_self.__calss__
  10. else:
  11. # class unbound method
  12. f_class = getattr(func, 'im_class', None)
  13.  
  14. # class methods, bound and unbound methods
  15. if f_class and hasattr(func, '__name__'):
  16. return '%s.%s' % (f_class.__name__, func.__name__)
  17.  
  18. # class or class instance
  19. if hasattr(func, '__call__'):
  20. # class
  21. if hasattr(func, '__name__'):
  22. return func.__name_
  23. # class instance
  24. return func.__class__.__name__
  25.  
  26. raise ValueError('Unable to determine a name for ')
Add Comment
Please, Sign In to add comment