Consider a scenario where there is a child class and a single parent class, ParentClass
. The goal is to override a method named my_method
from the parent class in the child class. I have seen two ways of calling the my_method
in the parent class when defining a similarly named method in the child class:
super().my_method(args)
ParentClass.my_method(self, args)
Which method is more common? Which one do you find clearer?
I have a feeling No. 1 is more common but I personally find No. 2 clearer. Because it makes the presence of self
explicit. It is worth noting that we drop the self
argument when calling an instance method on an instance of a class. Dropping the self
argument here may lead to confusion between these two cases. Therefore, in my opinion, No.2 should be preferred over No. 1.
I wonder what others think about the popularity and appropriateness of these two methods.
Note. A common example of my_method
is the __init__
method.