I realized that I do not need the attrgetter
passed as an argument. Using same idea I can simply use getattr(self, "n")
in a decorator without an argument.
def add(func):
def wrapper(self, *args, **kwargs):
return func(self, *args, **kwargs) + getattr(self, "n") # Get "n" from `self`
return wrapper
class Foo:
def __init__(self, n):
self.n = n
@add # No argument needed.
def multiply(self, multiplier):
return self.n * multiplier
print(Foo(5).multiply(2))