Overriding methods inherited from a superclass with methods from a mixin
michael.selik at gmail.com
Mon Jun 13 18:50:50 EDT 2016
On Mon, Jun 13, 2016 at 2:46 PM <alanqueiros at gmail.com> wrote:
> Thank you for your replies. I don't know if I'm quoting you correctly, I'm
> quite confused with Google Groups... not sure if it's a "forum", something
> like a mailing list, or both... or neither.
Mailing list. A "forum" in the metaphorical sense, not the sense of phpBB.
You're doing fine with quoting, though it would help to add who said what
when quoting multiple people.
since the correct order is from right to left,
Did you mean left-to-right?
Are you thinking of Java where there's only one parent class allowed and
you specify any extra interfaces you're implementing afterwards? Because
that's not what your code is doing.
Still, pretty much *no one* uses that order [mixin1, mixin2, base]. A quick
> Google search returns (at least in my "bubble") many blog articles from
> "notable" Python users with that order wrong.
Do you mind providing links? I haven't seen anyone "notable" make this
> > To me it makes sense. English reads left-to-right, so method
> lookups go left-to-right (and children before parents) in the inheritance
> > list.
> Basically I wasn't very confident the code was OK because my intuition
> said the right way to order the classes I was inheriting from was from left
> to right.
That is correct! Write them in the order you are prioritizing the
definitions. Overrides before bases, left to right.
> I don't see any sense in that analogy you made... sure English and most
> occidental languages read ltr, but I fail to see how it makes more sense to
> have the base class on the right and the mixins on the left. Basically, I
> think of the mixins like plugins of kinds, I'm "adding" functionality to
> that "base" class I'm inheriting from.
That's not a good metaphor for what's actually happening. For more detail,
check out Raymond's "super considered super" video (
> Don't take my word for it, Google multi inheritance or mixin in Python and
> let me know if you find someone who thinks it's "natural" to do it that way.
This might be a bit of selection bias. People who think it makes sense
might not have an incentive to write a blog post about it. People who don't
like it will thus be more vocal.
Ian Lewis seems to be ranked highly by Google (
I disagree with his assertion that "most people" read an inheritance
hierarchy top-down with the bases at the left. I think of inheritance as a
tree. Even if it is a diamond at some point, a depth-first-search of a tree
isn't far off from the truth. The root (base) is at the bottom, in my mind,
and the leaves are at the top.
More information about the Python-list