Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Doc error on super(cls,self)

Reply
Thread Tools

Doc error on super(cls,self)

 
 
David MacQuigg
Guest
Posts: n/a
 
      06-11-2004
I think there is a documentation error in both the Library Reference
section 2.1 and the Python 2.2 Quick Reference page 19. The
explanation for this function is:

super( type[, object-or-type])
Returns the superclass of type.

I could not get this function to work right until I realized that it
is searching the entire MRO, not just the superclasses of 'type'.
Here is a simple experiment to show the difference.

## Animal -> Mammal -> Feline -> Cat
## talk1() talk1() talk1()
## \ - - - -> Mammal2 - - - - - - -> /
## talk2()
>>> super(Mammal,cat1).talk2()

Mammal2: Fluffy says Purr
>>> super(Animal,cat1).talk2()

AttributeError: 'super' object has no attribute 'talk2'
>>> Cat.__mro__

(<class '__main__.Cat'>, <class '__main__.Feline'>,
<class '__main__.Mammal'>, <class '__main__.Mammal2'>,
<class '__main__.Animal'>, <type 'object'>)

The first call finds talk2, even though it is *not* in a superclass of
Mammal. The second call fails, because talk2 is not found in any
class above Animal in the MRO.

I think a better explanation would be:

super(cls,self).meth(arg)
This calls method 'meth' from a class in the MRO (Method Resolution
Order) of 'self'. The selected class is the first one which is above
'cls' in the MRO and which contains 'meth'.

I would like to get some feedback before submitting this as a bug.

-- Dave

 
Reply With Quote
 
 
 
 
Michele Simionato
Guest
Posts: n/a
 
      06-12-2004
David MacQuigg <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>. ..
> I think there is a documentation error in both the Library Reference
> section 2.1 and the Python 2.2 Quick Reference page 19. The
> explanation for this function is:
>
> super( type[, object-or-type])
> Returns the superclass of type.


Aha! Now I see why for a while in the past I thought 'super' was returning
the superclass: I had read the documentation!

The sentence you report here is clearly WRONG and misleading, since 'super'
returns a 'super object' which is a descriptor acting more or less as a proxy
to the methods in the MRO. 'super' by no means is returning the superclass.
So please submit the documentation bug. If nobody has already done that,
I will volunteer to write a tutorial on 'super', since it is rather tricky
and terribly documented in the standard docs.

Michele Simionato
 
Reply With Quote
 
 
 
 
David MacQuigg
Guest
Posts: n/a
 
      06-12-2004
On 11 Jun 2004 21:04:40 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) (Michele
Simionato) wrote:

>David MacQuigg <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>. ..
>> I think there is a documentation error in both the Library Reference
>> section 2.1 and the Python 2.2 Quick Reference page 19. The
>> explanation for this function is:
>>
>> super( type[, object-or-type])
>> Returns the superclass of type.

>
>Aha! Now I see why for a while in the past I thought 'super' was returning
>the superclass: I had read the documentation!
>
>The sentence you report here is clearly WRONG and misleading, since 'super'
>returns a 'super object' which is a descriptor acting more or less as a proxy
>to the methods in the MRO. 'super' by no means is returning the superclass.
>So please submit the documentation bug. If nobody has already done that,
>I will volunteer to write a tutorial on 'super', since it is rather tricky
>and terribly documented in the standard docs.


I will submit the bug report.

I think a tutorial would be very helpful. The only clear (but
lengthy) explanation I have found is GvR's paper at
http://python.org/2.2.3/descrintro.html#cooperation (see "Cooperative
methods and super" pp.14-18 in the printed version) I've tried to
condense this into a brief summary in my OOP chapter at
http://ece.arizona.edu/~edatools/Python/PythonOOP.doc (see "Super
Calls" on p.14-15). I could add your tutorial as an example or
exercise, or link to your website, if you have a relatively permanent
place.

-- Dave

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
.pdf doc to word doc PWB Computer Support 14 09-19-2008 10:41 PM
Ruby Socket: I found a misstake in the doc. Can someone confirm itand who's gonna fix this doc-error? kazaam Ruby 3 10-06-2007 01:46 PM
String[] files = {"a.doc, b.doc"}; VERSUS String[] files = new String[] {"a.doc, b.doc"}; Matt Java 3 09-17-2004 10:28 PM
Converting a org.jdom DOC to org.w3c DOC Praveen Chhangani XML 2 08-07-2003 08:22 AM
Parsing MS Word client doc into server-side doc... John Wallace ASP .Net 0 07-22-2003 06:49 PM



Advertisments