Just like the title says, do overridden methods inherit decorators?
class A: @memoized def fun(self, arg): return None class B(A): def fun(self, arg): #computations return something
so does B.fun() maintain the decorator?
If you want to add @override , the @override decorator can't actually do any override checking. You then have two options. Either there is no override checking, in which case @override is no better than a comment, or the type constructor needs to specifically know about @override and check it at class creation time.
In Python method overriding occurs by simply defining in the child class a method with the same name of a method in the parent class. When you define a method in the object you make this latter able to satisfy that method call, so the implementations of its ancestors do not come in play.
Decorators are a very powerful and useful tool in Python since it allows programmers to modify the behaviour of a function or class. Decorators allow us to wrap another function in order to extend the behaviour of the wrapped function, without permanently modifying it.
Method overriding in Python is when you have two methods with the same name that each perform different tasks. This is an important feature of inheritance in Python. In method overriding, the child class can change its functions that are defined by its ancestral classes.
Think about it this way
class A(object): def fun(self, arg): return None fun = memoized(fun)
No. It's a completely different function. But you can try that for yourself with a dummy decorator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With