I have the following situation in my Python code:
class Parent(object): def run(self): print "preparing for run" self.runImpl() print "run done" class Child(Parent): def runImpl(self): print "child running"
However, I have several such "decorators" that perform different configuration / detach steps before and after "runImpl", and I do not like to define run() , runImpl() , runImplSingleProcess() , etc.
I am looking for a solution of the following form:
class Parent(object): @wrapping_child_call def run(self, func_impl, *args, **kwargs) print "preparing for run" func_impl(*args, **kwargs) print "run done" class Child(Parent): def run(self): print "child running"
Thus, for the Child class, you hardly need to know about this.
Multiple inheritance issues may also occur. If a Child inherits from Parent1 and Parent2 , I honestly don't know how the correct behavior should be.
Does anyone know a good, natural way to do this? or did i rap the design here?
thanks
Jonathan
python inheritance decorator implementation wrapper
Yonatan
source share