Say I have a class, and I want to decorate one of its methods with another. Like in the example:
class Foobar:
def foo(self, func):
def wrapped(*args, **kwargs):
print(self + " is doing something")
func(*args, **kwargs)
return wrapped
@foo
def bar(self, *args, **kwargs):
print("Foobar")
Of course, when I make an instance of Foobar and run bar, an exception will be raised because the function gets passed to self and there's nothing for func. But I can't just decorate foo with staticmethod because self is needed to run the wrapped function.
This is quite a dilemma. Can someone help?