Why is this an ambiguous MRO?
1 2 3 4 5 6 7 8 9 10 11 | class First(object): def __init__(self): print"first" class Second(First): def __init__(self): print"second" class Third(First, Second): def __init__(self): print"third" |
来源
为什么python不能创建一致的mro?我觉得很清楚:
但是如果你尝试一下:
1 2 3 | TypeError: Error when calling the metaclass bases Cannot create a consistent method resolution order (MRO) for bases First, Second |
(P)To be"consistent"the Mro should satisfy these constraints:(p)
(P)你的建议不一定要召开这些会议。由于第三方被要求在第二方之前进行吸血,第一方应在第二方参加第三方会谈之前进行吸血。但是,由于第二个Inherits from First,Second should come before the Mro.这一矛盾不能被接受。(p)(P)You can read more about the precise method pyton used to compute the mro,which is called the C3 linarization algorithm.(p)