C3 MRO

Chris Angelico rosuav at gmail.com
Sat Nov 19 11:50:28 EST 2016


On Sun, Nov 20, 2016 at 3:21 AM, Victor Porton <porton at narod.ru> wrote:
> Do I understand correctly, than C3 applies to particular methods, and thus
> it does not fail, if it works for every defined method, even if it can fail
> after addition of a new method?
>
> Also, at which point it fails: at definition of a class or at calling a
> particular "wrong" method?

It either succeeds or fails for the entire class. If it fails, you get
an exception at class definition time:

class A: pass
class B: pass
class C(A, B): pass
class D(B, A): pass
class E(C, D): pass

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Cannot create a consistent method resolution
order (MRO) for bases A, B

ChrisA



More information about the Python-list mailing list