super(...).__init__() vs Base.__init__(self)

Jan Niklas Fingerle usenet-2004 at lithe.de
Sun Feb 12 15:59:33 EST 2006


Steven Bethard <steven.bethard at gmail.com> wrote:
> Jan Niklas Fingerle wrote:
> > Steven Bethard <steven.bethard at gmail.com> wrote:
> >> Personally, I'd call the lack of the super calls in threading.Thread and 
> >> Base bugs.  
> > 
> > It can't be a bug since it wasn't a bug before super was introduced and
> > you don't wan't to break working Python-2.x-code. 
> 
> Just because there wasn't a bugfix available at the time doesn't mean it 
> wasn't a bug. ;) 

Yes, but it isn't a bug. 

> The threading.Thread class does not properly call 
> sibling constructors in multiple inheritance. > This should either be 
> fixed in the implementation (by introducing a call to super) 

This would break existing code as shown in http://fuhm.org/super-harmful/
(look out for "Subclasses must use super if their superclasses do").
And as much as I agree with GvR that the word "harmful" is inappropriate
(http://mail.python.org/pipermail/python-dev/2005-January/050656.html),
I agree with both, that super is a part of your class's interface that
you might use or not. You just have to document it, whether you use
super, or not. Or to quote GvR: "Super is intended for use that are 
designed with method cooperation in mind [...]". That's isn't "always".

The best pratices (see any of the two URLs above) obviously show, that
using super comes at some cost. This is OK, if you really have to
support cooperative method calling. But I wouldn't want to pay it "just
in case".

> or fixed in 
> the documentation 

This is true, but this or the other way round: You have to document,
that you're using super(), or that you don't do it. 

> (by indicating that threading.Thread does not support 
> multiple inheritance in its __init__() method).

It *does* support multiple inheritance, it just doesn't support diamond
shape inheritance (not counting object). 

> I've used diamond inheritance exactly once, and all the classes under 
> that hierarchy were under my control, so they all used super properly. 

And this is, what super() is meant for. I, for my part, won't use 
super() until I really need it, but when the time comes I will 
worship an extra hour at my Guido-van-Rossum-shrine. ;-)



More information about the Python-list mailing list