I try to implement a decorator class and it works fine if I call it with parentheses, but if I try to use it without parentheses it does not work.
How can I make it work without calling it directly if no arguments are passed?
class DecByClass:
def __init__(self, retry=None, *args, **kwargs):
self._retry = retry
def __call__(self, func, *args, **kwargs):
def wrapper(*args, **kwargs):
retval = func(*args, **kwargs)
return retval
return wrapper
This works:
@DecByClass()
def try_brackets(t):
return '2'
This doesn't:
@DecByClass
def try_brackets(t):
return '2'
What have I missed?