I'm trying to annotate a decorator implemented as a class, but mypy seems to either lose the annotation or lose the type and think it's an Any. What I am trying to annotate:
class my_decorator:
def __init__(self, func):
self.func = func
def __call__(self, *args, **kwargs):
return self.func(*args, **kwargs)
@my_decorator
def func():
return 2
How do I annotate this so func is detected as returning an int after decorating? I realize the above looks simple and I could convert my_decorator to a function, but in reality it is subclassed to have more specialized options.