On Sun, Oct 20, 2019 at 9:06 PM Ian Hobson <hobso...@gmail.com> wrote:
>
> Hi Jach,
>
> On 20/10/2019 09:34, jf...@ms4.hinet.net wrote:
> > What puzzles me is how a parent's method foo() can find its child's method 
> > goo(), no matter it was overwrote or not? MRO won't explain this and I 
> > can't find document about it also:-(
>
> This is a generalised description - Python may be slightly different.
>
> When foo invokes goo the search for goo starts at the class of the
> object (which is B), not the class of the executing method (i.e not A).
> It then proceeds to look for goo up the class hierarchy - first in B,
> then A then Object.
>

Yeah, pretty much. In a simple case of linear inheritance, that's how
it works in Python. There are complexities with multiple inheritance
and different languages will do things differently, but that doesn't
affect this example.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to