What's the purpose the hook method showing in a class definition?
Ian Hobson? 2019?10?20???? UTC+8??6?05?11????
> Hi Jach,
> On 20/10/2019 09:34, jfong at 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.
> If that fails the RTS modifies the call, to look for a magic method, and
> starts again at B. When the magic method is found in Object, you get the
> "not found" error. If you implement the magic method in A or B it will
> be run instead.
> This email has been checked for viruses by AVG.
I see. An obj.method will be resolved according to the MRO of the obj's class, no matter where it is located. Thank you.