Calling __init__ for all mixins

Michael Hudson mwh at python.net
Thu Aug 19 13:39:42 EDT 2004


Martin Maney <maney at pobox.com> writes:

> Shalabh Chaturvedi <shalabh at cafepy.com> wrote:
> > The new-style super mechanism might indeed solve your problem. In the 
> > snippet that you mention, super(NewStyleOnly, self).__init__() would 
> > only call A.__init__(). But A.__init__ should itself have a super call 
> > of the form:
> 
> > def __init__(self):
> >     super(A, self).__init__()   # A's super call
> 
> > Now *that* will call B.__init__(), which should itself have a super call 
> 
> I will be dipped in shit.  So let me see... super(this_here_class,
> self) can and will resolve to a class that is not in any sane meaning
> of the word a super class of this_here_class, but rather a co-base of
> it?

No.  super(this_here_class, self) returns, well, a super() object that
when you look for an attribute on it acts a bit like `self.__class__'
but only looks in classes later than `this_here_class' in the MRO.

Don't worry too much if that didn't make sense, but it's probably a
good idea to get the thought that super() returns a class out of your
head.

> This is either brilliant or pure crack.  I'll have to ponder it for
> a good long while.

It's brilliant :-)

Cheers,
mwh

-- 
  > Well, as an American citizen I hope that the EU tells the MPAA 
  > and RIAA to shove it where the Sun don't shine.
  Actually they already did. Only first they bent over and dropped
  their trousers.      -- Shmuel (Seymour J.) Metz & Toni Lassila, asr



More information about the Python-list mailing list