4 ms·
The method resolution order for instances of the same class is always the same for all methods. If the class doesn't implement that method, the interpreter just
by alextp 15y ago
The method resolution order for instances of the same class is always the same for all methods. If the class doesn't implement that method, the interpreter just skips and goes to the next place in the call chain. All super does is call the next method in the chain. So if you have class A(object), class B(A), class C(A), and class D(B, C), the MRO of D's instances will be B C A object. Each time an instance of D calls super, it will call the next method in the chain, not necessarily B's or C's or A's, even if the call to super is in B's method. This is why super() receives the class as a parameter, so it can know from when in the object's mro to start looking up the next method.
- veyron 15y ago"This is why super() receives the class as a parameter" <-- this is not necessary in python 3. Your argument is valid in python2, but python3 allows a super() call without a type argument. From the docs: "super(type[, object-or-type])" <-- python2 doc, type is required "super([type[, object-or-type]])" <-- type is optional in python3