Slightly modifying the answer from Applying python decorators to methods in a class, it is possible to apply a decorator to every method in a class. Is there any way to do this without the inspect module? I’ve been trying to accomplish this using metaclasses and modifying __getattribute__ but I keep getting infinite recursion. From How is the __getattribute__ method used?, this can be fixed in normal classes using object.__getattribute__(self, name). Is there anything equivalent for metaclasses?
Slightly modifying the answer from Applying python decorators to methods in a class ,
Share
Define a meta class and then just apply decorator at the end of class definition.
For Python 3 just replace the
types.UnboundMethodTypewithtypes.FunctionType.but if you really don;t wanna use inspect than you can do it like this
Note: it will not decorate staticmethod and classmethod