Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #6799

Re: Updated blog post on how to use super()

References <80476fba-1b57-4bb1-9d7d-391edaf3042d@22g2000prx.googlegroups.com> <is5dbe$n76$1@speranza.aioe.org>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2011-06-01 10:42 -0600
Subject Re: Updated blog post on how to use super()
Newsgroups comp.lang.python
Message-ID <mailman.2368.1306946563.9059.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Jun 1, 2011 at 7:03 AM, Billy Mays <noway@nohow.com> wrote:
> I read this when it was on HN the other day, but I still don't see what is
> special about super().  It seems (from your post) to just be a stand in for
> the super class name?  Is there something special I missed?

It's not a stand-in for the super-class name.  It's a stand-in for
whatever class is next in the Method Resolution Order (MRO), which is
determined at run-time and can vary depending on what the actual class
of the object is.  For example, in this inheritance situation:

class A(object):
    ...

class B(object):
    ...

class C(A, B):
    ...

a = A()
c = C()

The MRO of A is (A, object).
The MRO of B is (B, object).
The MRO of C is (C, A, B, object).

Thus, super(A, a) is going to resolve to object, as you might expect.
But super(A, c) is going to resolve to B, because the next class after
A in the MRO for C instances is B.

That's a pretty quick and dirty explanation.  If it doesn't make
sense, I suggest reading the article again.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Updated blog post on how to use super() Raymond Hettinger <python@rcn.com> - 2011-05-31 19:44 -0700
  Re: Updated blog post on how to use super() Ben Finney <ben+python@benfinney.id.au> - 2011-06-01 14:26 +1000
  Re: Updated blog post on how to use super() Billy Mays <noway@nohow.com> - 2011-06-01 09:03 -0400
    Re: Updated blog post on how to use super() Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-01 10:42 -0600
      Re: Updated blog post on how to use super() Billy Mays <noway@nohow.com> - 2011-06-01 12:46 -0400
        Re: Updated blog post on how to use super() Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-01 11:06 -0600
        Re: Updated blog post on how to use super() Chris Torek <nospam@torek.net> - 2011-06-01 17:43 +0000
    Re: Updated blog post on how to use super() Duncan Booth <duncan.booth@invalid.invalid> - 2011-06-02 20:58 +0000

csiph-web