Martin von Loewis loewis at
Mon Feb 18 17:46:12 CET 2002

Gustavo Niemeyer <niemeyer at> writes:

> AFAICS, this seems to be the most useful version of super:
> super(obj.__class__, obj)

It would usually be wrong. Consider

class Base(object):
  def doit(self):

class Derived1(Base):
  def doit(self):
    super(Derived1, self).doit()

class Derived2(Derived1):
  def doit(self):
    super(Derived2, self).doit()

obj = Derived2()

This could does the expected: Derived2.doit call2 Derived1.doit calls
Base.doit. If you change Derived1 to

class Derived1(Base):
  def doit(self):
    super(self.__class__, self).doit()

then self.__class__ would be Derived2, so the Derived1 would call
itself recursively, instead of performing a super call.


More information about the Python-list mailing list