Question

I read this doc today. There is something confused me.

http://www.python.org/download/releases/2.3/mro/

In the example to prove the MRO of Python 2.2 breaks monotonicity,

>>> class A(object): pass
>>> class B(object): pass
>>> class C(object): pass
>>> class D(object): pass
>>> class E(object): pass
>>> class K1(A,B,C): pass
>>> class K2(D,B,E): pass
>>> class K3(D,A):   pass
>>> class Z(K1,K2,K3): pass

I think the result that Python 2.2 will give linearizations for Z is:['Z', 'K1', 'C', 'K2', 'B', 'E', 'K3', 'D', 'A', 'object'], however, the doc gives L[Z,P22] = Z K1 K3 A K2 D B C E O

and the doc said, this example is originally provided by Samuele Pedroni in here, and Samuele Pedroni's answer is the same as mine.

Is there anything I missed?

Was it helpful?

Solution

I think the result that Python 2.2 will give linearizations for Z is:['Z', 'K1', 'C', 'K2', 'B', 'E', 'K3', 'D', 'A', 'object']

Why do you think that?

A quick try:

Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class A(object): pass
...
>>> class B(object): pass
...
>>> class C(object): pass
...
>>> class D(object): pass
...
>>> class E(object): pass
...
>>> class K1(A,B,C): pass
...
>>> class K2(D,B,E): pass
...
>>> class K3(D,A):   pass
...
>>> class Z(K1,K2,K3): pass
...
>>> Z.__mro__
(<class '__main__.Z'>, <class '__main__.K1'>, <class '__main__.K3'>, <class '__m
ain__.A'>, <class '__main__.K2'>, <class '__main__.D'>, <class '__main__.B'>, <c
lass '__main__.C'>, <class '__main__.E'>, <type 'object'>)
>>>

So the MRO for Z is Z K1 K3 A K2 D B C E object, so the docs seem to be correct.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top