문제

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?

도움이 되었습니까?

해결책

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.)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top