python - How can I apply decorator to a superclass method in a subclass? -


say, have following situation,

class a():     def something():         ...         ...         ...   class b(a):     def use_something():         ...         ...         # now, @ point want something() decorated          # decorator. but, since defined in base class,          # not getting how decorate here, in subclass.         self.something()         ...         ... 

now, in class b, want use something() class a, want apply decorator it. cannot decorate in class a, since there different decorators want apply @ different places. say, class c(a) , want use something() here well, different decorator.

so, coming original question; how can apply decorator superclass's method in subclass?

any particular reason why can't override something()?

class a():     def something(self):         ...  class b(a):     def use_something(self):         ...         self.something()         ...      def something(self):         # "decorator" stuff         super().something()         # more "decorator" stuff 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -