| Store | Cart

Calling __init__ with multiple inheritance

From: Peter Otten <__pe...@web.de>
Mon, 28 Mar 2005 19:51:31 +0200
jfj wrote:

> 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.

I agree.
 
> 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.

Peter

Recent Messages in this Thread
Axel Straschil Mar 28, 2005 12:51 pm
Peter Otten Mar 28, 2005 02:08 pm
jfj Mar 29, 2005 03:27 am
Peter Otten Mar 28, 2005 05:51 pm
jfj Mar 29, 2005 04:53 am
Peter Otten Mar 28, 2005 07:53 pm
Axel Straschil Mar 29, 2005 05:53 am
Steven Bethard Mar 29, 2005 07:02 am
Peter Otten Mar 29, 2005 08:37 am
Axel Straschil Mar 29, 2005 12:21 pm
jfj Mar 29, 2005 07:38 pm
Robert Dick Mar 28, 2005 07:14 pm
phil...@yahoo.com Mar 28, 2005 04:07 pm
Messages in this thread