[Tutor] class questions

Hugo Arts hugo.yoshi at gmail.com
Sun Jun 27 18:32:40 CEST 2010


On Sun, Jun 27, 2010 at 4:13 PM, Payal <payal-python at scriptkitchen.com> wrote:
> Hi Hugo,
>
> On Sun, Jun 27, 2010 at 01:27:37PM +0200, Hugo Arts wrote:
>> Here's my attempt. Consider this simple Diamond hierarchy:
> [...]
>> Now, with this diagram the following code probably doesn't do what you expect:
>
> Actually, it does what is expected. The old mro specifically says,
> bottom-top, left-right. So we expected D-B-A-C-A.
> Steven says in some cases even this simple logic of bottom-top,
> left-right search will not work. As he says, a simple example of it
> failing is diffclt to write, so meanwhile I will take his word for it.
>

The problem of the MRO isn't that it doesn't work, it's that it causes
behavior that is unintuitive. In my example, We would expect D.x to be
equal to C.x (since D inherits from C, and C overrides the x method).
However, this is not the case. This is what the problem is with the
old MRO system, not so much that it doesn't work at all, but the
results aren't consistent with what you'd expect from multiple
inheritance.

I just found this link, where Guido explains why he changed the MRO
system for new-style classes. He uses the same example I do.

http://www.python.org/download/releases/2.2.2/descrintro/#mro

Hugo


More information about the Tutor mailing list