[Python-ideas] MRO local precedence ordering revisited
Ian Kelly
ian.g.kelly at gmail.com
Thu Dec 10 16:58:37 EST 2015
On Thu, Dec 10, 2015 at 1:51 PM, Stephan Sahm <Stephan.Sahm at gmx.de> wrote:
> @Ned
> As I understood it, the MRO is not only for searching attributes - there it
> is indeed impressively redundant to put the same class twice into the MRO,
> thanks for pointing that out - but also for the hierarchy of the super()
> command
In that situation including the class twice results in an infinite
loop. If your MRO is (B, mixin, A, mixin, object), then the chain of
super calls looks like this:
super(B, self).method()
super(mixin, self).method()
super(A, self).method()
super(mixin, self).method()
super(A, self).method()
...
This happens because the second super call from the mixin class is
identical to the first one. super doesn't know which appearance of
mixin based on the arguments passed it, and if it naively assumes the
first appearance, then nothing after the second appearance of mixin
will ever be reached.
More information about the Python-ideas
mailing list