super() doesn't get superclass

Hrvoje Niksic hniksic at xemacs.org
Wed Sep 19 03:31:57 EDT 2007


Ben Finney <bignose+hates-spam at benfinney.id.au> writes:

> Evan is claiming that "the next class in the MRO _is_ a superclass",
> apparently by his definition or some other that I've not seen.

The definition of superclass is not the issue, the issue is
"superclass *of which class*"?  You expect super(A, self) to iterate
only over superclasses of A, even when self is an instance of a
subtype of A.  What really happens is that super(A, self) yields the
next method in type(self)'s MRO, which can and does cause include
classes that are not by any definition superclasses of A.  All of
those classes are, however, superclasses of the instance's type.

I think it is not possible to have super(A, self) only call
superclasses of A and at the same time having multiple inheritance
work without calling some methods in the hierarchy twice or not at
all.  Guido's paper at http://tinyurl.com/qkjgp explains the reasoning
behind super in some detail.

>> I agree that the documentation for super is somewhat misleading (and
>> obviously wrong),
>
> Well, that's the first time someone has acknowledged that in this
> thread, so I guess this is something.

For the record, I also agree with that.  The documentation should
document in some detail that super(type, obj) yields superclasses of
type(obj), not of type, and that the "type" argument is only used for
super to be able to locate the next type in the list.

>> I wouldn't use such an extreme word as 'madness', but I totally agree
>> that this should be corrected. Care to submit a doc patch ?
>
> I don't understand what practical uses 'super' is intended for

It's intended for cooperative multiple inheritance, a la CLOS's
call-next-method.



More information about the Python-list mailing list