super and __init__
noah at noah.org
Sat Sep 9 00:59:23 CEST 2006
> Noah wrote:
> > Am I the only one that finds the super function to be confusing?
> Unfortunately, I don't see a way of avoiding this problem with super().
> Any such super command resolves in the mro order. Since the mro order
> invoked at a certain class can change depending on its subclasses,
> there's no way for the class to predict at design time what super() is
> going to return. You can predict what will be returned with your class
> hierarchy, but another programmer can create a multiple-inheritence
> class that will change the result.
> Explicitly calling the base class is much easier, but a given class
> method can be called multiple times in that case.
If I know that multiple calls to my base class __init__ is harmless
and multiple calls to my derrived class __init__ is harmless then
is it best to just go ahead and use the old style of explicitly calling
the __init__? I'm just worried about using the old style base __init__
with new style objects.
Since inheritance is so fundemental to an object oriented language
it's bad that Python makes it so easy to get the constructor wrong.
More information about the Python-list