method resolution order - Python's document about MRO is wrong? -


i read doc today. there confused me.

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

in example prove 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 result python 2.2 give linearizations z is:['z', 'k1', 'c', 'k2', 'b', 'e', 'k3', 'd', 'a', 'object'], however, doc gives l[z,p22] = z k1 k3 k2 d b c e o

and doc said, example provided samuele pedroni in here, , samuele pedroni's answer same mine.

is there missed?

i think result python 2.2 give linearizations z is:['z', 'k1', 'c', 'k2', 'b', 'e', 'k3', 'd', 'a', 'object']

why 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" 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 mro z z k1 k3 k2 d b c e object, docs seem correct.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -