I have a class with a dull repeating pattern on their functions and I wanted to turn this pattern into a decorator. But the thing is that this decorator must access some att
The decorator gets only one parameter – the function or method it decorates. It does not get passed an instance as self
parameter – at the moment the decorator is called, not even the class has been created, let alone an instance of the class. The instance will be passed as first argument to the decorated function, so you should include self
as first parameter in the parameter list of call()
.
I don't see the necessity to include the decorator in the class scope. You can do this, but you can just as well have it at module scope.