python - How to indentify if a function being decorated is a function or a method? -
this question has answer here:
how can identify if current function being decorated method (belonging class) or function?
class classa: @mydecorator def method(self) pass @staticmethod @mydecorator def function() pass
mydecorator need know if decorated function is:
- a method (is_method)
- a static method (is_static)
- a class method (is_classmethod)
- a global function (is_function)
how can this?
thanks!
is_method = lambda f: hasattr(f, 'im_self') is_static = lambda f: isinstance(f, types.functiontype) is_classmethod = lambda f: getattr(f, 'im_self', none) not none is_function = lambda f: not hasattr(f, 'im_self')
Comments
Post a Comment