Re: Things to know about ‘super’ (was: super() and multiple inheritance failure)

Michele Simionato michele.simionato at gmail.com
Sat Sep 26 01:58:32 EDT 2009


On Sep 26, 6:56 am, Ben Finney <ben+pyt... at benfinney.id.au> wrote:
> Michele Simionato <michele.simion... at gmail.com> writes:
> > You may want to read "Things to know about super":
>
> >http://www.artima.com/weblogs/viewpost.jsp?thread=236275
> >http://www.artima.com/weblogs/viewpost.jsp?thread=236278
> >http://www.artima.com/weblogs/viewpost.jsp?thread=237121
>
> Thanks for these articles. Any chance they will appear in a single
> location, so we don't need three separate URLs for them?

Good idea. I have collect them in PDF form here:
http://www.phyast.pitt.edu/~micheles/python/super.pdf

> Also, one article passes on this recommendation:
>
>     use super consistently, and document that you use it, as it is part
>     of the external interface for your class, like it or not.

(this is a literal citation from "super considered harmful" by James
Knight)

>     So, if use classes coming from a library in a multiple inheritance
>     situation, you must know if the classes were intended to be
>     cooperative (using super) or not. Library author should always
>     document their usage of super.
>
> I can see lots of ways this fact could be documented, none of them
> terribly concise. It's a simple “yes/no” fact about a class, after all;
> what's the best way of succinctly conveying this information in a world
> where the problem is barely known, let alone the solution?

Difficult question. You know that in an ideal world I would just
throw
away multiple inheritance, it is just not worth the complication.
In the real world, this is how a developer can document his hierarchy
in one-line:

class Base(object):
    "This hierarchy use super. See http://fuhm.net/super-harmful"

or

class Base(object):
    "This hierarchy does not use super. See http://fuhm.net/super-harmful"

That's all that is needed to third party code wanting to inherit from
the hierarchy.



More information about the Python-list mailing list