super() doesn't get superclass

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Thu Sep 20 06:16:33 CEST 2007


On Thu, 20 Sep 2007 13:36:41 +1000, Ben Finney wrote:

> Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> writes:
> 
>> On Thu, 20 Sep 2007 12:00:40 +1000, Ben Finney wrote:
>> 
>> > In its latter form, it is worthless to me when I'm looking for "get
>> > superclass of A", but its name and parameters and documentation all
>> > lead me very strongly to believe otherwise.
>> 
>> Why are you looking for the superclass of A?
> 
> Currently irrelevant to the point. Whether for good or bad reasons, I
> looked for a way to "get the superclass of A". 

A.__base__ and A.__bases__ are, I believe, the "right" way to do that.


> Everything about 'super'
> — its name, parameter semantics, and documentation — all firmly led me
> to believe that was the correct function for that purpose.

Name, I can accept.

Parameter semantics? That's borderline. "Get the superclass of A" looks 
like it should take ONE and ONLY one argument, namely A. super() 
typically takes two arguments, and only in non-typical use does it take a 
single argument.

And documentation? From help(super):


class super(object)
 |  super(type) -> unbound super object
 |  super(type, obj) -> bound super object; requires isinstance(obj, type)
 |  super(type, type2) -> bound super object; requires issubclass(type2, 
type)
 |  Typical use to call a cooperative superclass method:
 |  class C(B):
 |      def meth(self, arg):
 |          super(C, self).meth(arg)


Hmmm... it says it returns a super object, not a type or a class and 
certainly not "the superclass". It doesn't say what a super object 
actually is, but it doesn't say it is a type, or it would say "returns a 
type object". Nor does it say it returns the superclass -- it doesn't 
even use the term, with or without the hyphen.

And with a typical example shown right there, so close to the top, the 
documentation is pretty clear that super() doesn't do what you imagined 
it does.

So while I accept that the name of super() is misleading, I don't accept 
that the documentation is misleading. Incomplete, yes, hard to 
understand, yes, but not misleading. 

At least, it didn't mislead _me_, and I'm pretty gullible sometimes... 
*wink*



-- 
Steven.



More information about the Python-list mailing list