super() in class defs?
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Wed May 25 17:40:32 EDT 2011
On Wed, 25 May 2011 12:31:33 -0600, Ian Kelly wrote:
> I would recommend against using super() in general.
>
> http://fuhm.net/super-harmful/
If you actually read that article, carefully, without being fooled by the
author's provocative ex-title and misleading rhetoric, you will discover
that super is not harmful. What is harmful is making unjustified
assumptions about what super does, and about the code you are calling,
and hence misusing super.
You have to read all the way to the bottom of the article to see the
author say in the TODO section:
"Give some examples of why super really is necessary sometimes"
Even before that, you will read why *not* using super often fails badly.
If James Knight, the author, is correct that super is harmful, it seems
that you're in trouble because *not using super* is also harmful.
If you search the mailing lists of python-dev at python.org, you will find a
debate between James and Guido van Russum where James eventually
acknowledges that he is wrong to call super harmful. There's a reason
that he has changed the title of the page from "Python's Super Considered
Harmful" to the damning-with-faint-praise "Python's Super is nifty, but
you can't use it".
The new title is also *simply wrong*, because you can use it. James even
tells you what you need to do to use it correctly.
The truth is that for multiple inheritance, you better be using super or
your code is probably buggy (unless you manually duplicate what super
does for you). And for single inheritance, it makes no difference whether
you use super or not.
--
Steven
More information about the Python-list
mailing list