Doc error on super(cls,self)

Discussion in 'Python' started by David MacQuigg, Jun 11, 2004.

  1. 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
    David MacQuigg, Jun 11, 2004
    #1
    1. Advertising

  2. David MacQuigg <> wrote in message news:<>...
    > 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
    Michele Simionato, Jun 12, 2004
    #2
    1. Advertising

  3. On 11 Jun 2004 21:04:40 -0700, (Michele
    Simionato) wrote:

    >David MacQuigg <> wrote in message news:<>...
    >> 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
    David MacQuigg, Jun 12, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    3
    Views:
    479
    Tor Iver Wilhelmsen
    Sep 17, 2004
  2. Guest

    super.super.super how?

    Guest, Feb 19, 2005, in forum: Java
    Replies:
    24
    Views:
    10,742
    Darryl Pierce
    Feb 24, 2005
  3. james_027

    cls & self

    james_027, Jul 26, 2007, in forum: Python
    Replies:
    3
    Views:
    309
    Chris Mellon
    Jul 27, 2007
  4. J Peyret
    Replies:
    10
    Views:
    421
    Steven D'Aprano
    Mar 19, 2011
  5. Steven D'Aprano

    Style question: metaclass self vs cls?

    Steven D'Aprano, Jul 16, 2012, in forum: Python
    Replies:
    6
    Views:
    226
    Steven D'Aprano
    Jul 18, 2012
Loading...

Share This Page