I have a decorator
def deco(func):
def inner(params):
#< DO STUFF WITH func >
return inner
And a base class
class GenericClass:
def __init__(self,value):
self.value = value
def method(self,params):
print 'NOT IMPLEMENTED YET'
def other_method(self):
print 'GOOD TO GO'
I would like to be able to decorate the "method" method on classes which are child of GenericClass, for exemple to check input/output or handle exceptions (the method "method" will be overrided)
what I want to do is something like...
class ChildClass(GenericClass):
@deco
def method(self,params):
#< NEW METHOD >
I am not an expert python developper and all the doc at that level is quite confusing (i.e. metaclasses, subtleties in decorators, __call__
method etc etc) and I didn't found the solution on SO.
params
in thedeco
, otherwise, you would have to access them withargs[index]
where index could be shifted i.e. first actual argument for function has index 0 and for method it will be 1. You can use negative indices for simplicity but only if the number of arguments is constant – Frap