[Python-ideas] MRO local precedence ordering revisited

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Dec 10 18:11:16 EST 2015


Stephan Sahm wrote:
>     class Mixin(object):
>         pass  
> 
>     class A(Mixin):
>         pass
>     class B(Mixin, A):
>        pass
> 
> 
> this unfortunately throws "TypeError: Error when calling the metaclass 
> bases Cannot create a consistent method resolution order (MRO) for bases 
> A, Mixin"

The reason Python disallows this is that B is saying that
methods of Mixin should override those of A, whereas A is
saying that its own methods should override those of
Mixin. So there is a potential for B to break A's
functionality.

It may be that nothing gets broken in your particular
case, but Python can't know that in general, so it errs
on the safe side.

-- 
Greg


More information about the Python-ideas mailing list