Calling __init__ with multiple inheritance
__peter__ at web.de
Mon Mar 28 19:51:31 CEST 2005
> Peter Otten wrote:
>> Here is an alternative approach that massages the initializer signatures
>> a bit to work with super() in a multiple-inheritance environment:
>> super(Father, self).__init__(p_father=p_father, **more)
> Is there any advantage using super in this case?
> I think the case Father.__init__ (self, params) is simpler
> and does the job perfectly well.
> super seems to be needed in "Dynamic Inheritance" cases where
> we don't know an object's bases and there are comlicated mro issues!
Suppose you wanted factor out common code from the Father and Mother classes
into a Parent class -- something neither complicated nor farfetched. With
explicit calls to Parent.__init__() you would end up calling it twice from
Child.__init__(). So when you anticipate that your class hierarchy may
change, or that your classes may be subclassed by users of your library, I
think super() is somewhat less errorprone.
More information about the Python-list