calling superclass __init__ when superclass is object

Evan Klitzke evan at yelp.com
Thu Aug 2 01:53:55 EDT 2007


On 8/1/07, Evan Klitzke <evan at yelp.com> wrote:
> Hi list,
>
> I was reading this article: http://fuhm.net/super-harmful/ and didn't
> understand the comment about calling super(Foo, self).__init__() when
> Foo inherits only from object. Can someone on the list elaborate more
> on why one should do this?

I hate to reply to my own thread, but I read this article:
http://www.python.org/download/releases/2.3/mro/ and I think I
understand the rationale now. If you have:

class Foo(object):
    # stuff here
class Bar(object):
    # stuff here
class Baz(Foo, Bar):
    # stuff here

Then if Baz calls super(Baz, self).__init__() in its __init__, and Foo
makes no call super(Foo, self).__init__(), then the constructor for
Bar will never be called.

-- 
Evan Klitzke <evan at yelp.com>



More information about the Python-list mailing list