Question

I understand MRO is the order in which an attribute is found in class hierarchy.

If I use attribute 'foo' as in myInstance.foo, the first foo found in MRO will be used.
And the lookup will stop usually.

Now, suppose bar() utilizes super().
Since super() returns the next base instance in MRO, myInstance.bar() will call all the bar() in its hierarchy chain.

If all super classes's bar() also calls super().bar(),
bar() will be called in the order as MRO specifies.

Am I understanding them correctly?

Was it helpful?

Solution

Yup. (super is a bit more complex than "returns the next base instance in MRO", but you understand what attribute lookup on the returned object does, and that's what matters.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top