I understand that the best way to call a method in a superclass in python is to wirte:
class Foo(Bar):
def foo(self):
...
super(Foo, self).foo()
...
However, this means that if I change the name of the class Foo or I cut and paste the code in another class I have to remember to change the line that calls the method in the super class. Is there any way to get around this? At a minimum is annoying, at worst is very error prone.
In Python 3 you can write
super()and it will fill in the class for you.In Python 2 you need to write the name of the class. But changing the names of classes isn’t exactly a common operation, so I don’t really see that as much of a hardship. You just need to remember to search-and-replace for the name of the class if you change it — but then you’ll probably have to do that anyway, because its subclasses will refer to it by name as well.