Mixin classes and single/multiple inheritance (was: super() doesn't get superclass)
michele.simionato at gmail.com
Thu Sep 20 05:11:04 CEST 2007
On Sep 20, 4:55 am, Ben Finney <bignose+hates-s... at benfinney.id.au>
> Michele Simionato <michele.simion... at gmail.com> writes:
> > I am not against mixins (even if I am certainly very much against
> > the *abuse* of mixins, such as in Zope 2). What I would advocate
> > (but I realize that it will never happen in Python) is single
> > inheritance + mixins a la Ruby.
> For those unfamiliar with Ruby, could you explain how you see this
> being done in Python?
I don't see this being done in Python, it is too late now (for
backward compatibility and all that). But you can still do it
by yourself, the simplest thing being copying the methods
of the mixin class. It is already possible to use a syntax
mixin(Mixin1, Mixin2, ...)
using P.J. Eby's trick for implementing what he calls class
decorators (see also http://www.phyast.pitt.edu/~micheles/python/classinitializer.html)
But I would not use it, let's use the language we have, not
to invent our own.
> What do you see as an appropriate use of mixin classes, and what an
An example of fine usage of mixin is Tkinter; an example of
bad usage if Zope 2. In any case, I think using composition
in the end is a better solution than mixins (it
is much more scalable).
> What would the semantics be in Python for "single inheritance + mixins
> a la Ruby"? Can you give example syntax?
Already done. Since all hierarchies would be flat, super syntax
would be trivial as in Ruby/Java/etc (self.super.meth(args, kw)).
More information about the Python-list