Which class method will be used when calling it?

Patrick K. O'Brien pobrien at orbtech.com
Sat Mar 16 17:41:41 EST 2002


"Jeff Shannon" <jeff at ccvcorp.com> wrote in message
news:3C9290A7.AA3931CB at ccvcorp.com...
>
> Now it becomes a bit more difficult to figure out which version of f() is
> called.  In Python 2.1 and earlier, the base classes are searched
> depth-first, so that the call would resolve to B.f(), but if class D were
> declared as D(C, B) [note reverse order of ancestors], then d.f() would
> resolve to A.f() (since C has no f(), but C's parent A does).  Python 2.2
> changed this, so that (in essence) a breadth-first search is done; under
> 2.2, d.f() should resolve to B.f() regardless of the order that the
parents
> were listed when D was declared.
>
> (At least, I *think* I'm remembering this correctly.... ;) )
>

Classic classes resolve this as they always have, even under Python 2.2.
Only new style classes follow the new mechanism.

Details: http://www.python.org/2.2/descrintro.html#mro

--
Patrick K. O'Brien
Orbtech







More information about the Python-list mailing list