Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?
Jean-Michel Pichavant
jeanmichel at sequans.com
Fri Jul 30 08:43:07 EDT 2010
Steven D'Aprano wrote:
> On Fri, 30 Jul 2010 19:37:29 +1200, Gregory Ewing wrote:
>
>
>> Steven D'Aprano wrote:
>>
>>> On Thu, 29 Jul 2010 19:29:24 +0200, Jean-Michel Pichavant wrote:
>>>
>> >
>>
>>>> "mro" would have been the proper name for "super".
>>>>
>>> That's your opinion. In any case, whether super() was called super() or
>>> mro() or aardvark() makes no difference to the functionality or whether
>>> it is useful.
>>>
>> I think the point is that the name is misleading, because it makes it
>> *sound* like it's going to call a method in a superclass, when it fact
>> it might not.
>>
>
> I'm not sure I understand your point here. If you call super() from a
> method that doesn't exist in any superclass, then you are correct, it
> won't call a method in a superclass, and will raise AttributeError.
>
> But in the more sensible case that you only call super() when there is
> actually something to inherit, then of course it calls the method in a
> superclass. It certainly doesn't call methods from arbitrary unrelated
> classes, only those which are in the MRO. That is, superclasses.
>
> If Z is below A in the hierarchy, then we have no difficulty in
> identifying Z as a subclass of A, and likewise we should have no problem
> with identifying A as *a* (and not "the") superclass of Z, no matter how
> distant they are or how tangled the DIG between them.
>
> The exception would be if you could have loops in the class hierarchy, in
> which case the concepts of super- and sub-classes breaks down completely.
> But even if some other languages allowed that, Python doesn't, so we're
> safe.
>
>
>
>
Quoting Michele's article (I think he's still hanging around this list)
"Readers familiar will single inheritance languages, such as Java or
Smalltalk, will have a clear concept of superclass in mind. This
concept, however, has /no useful meaning/ in Python or in other multiple
inheritance languages".
the complete article on super:
http://www.artima.com/weblogs/viewpost.jsp?thread=236275
super is a strange name for something that makes no sense in python
(talking about superclass here). It doesn't take away the usefulness of
super, but it's a proof that you can ruin a good feature with a bad name.
JM
More information about the Python-list
mailing list