decorating a method in multiple child classes

1

1x7y2z9

Say, we have a (parent) class P.
It has N child classes C1(P), C2(P) ... CN(P)

Each of the child classes defines (differently) a method func().

I wish to decorate all of the CX.func() in the same way. One way to
do this is to add a decorator to each of the derived classes. But
this is tedious and involves modifying multiple files.

Is there a way to modify the parent class and have the same effect?
Or some other way neater than the above?

Thanks.



visual:
class P(object):
...

class C1(P):
def func(self, ...):
...

class C2(P):
def func(self, ...):
...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top