[docs] [issue37176] super() docs don't say what super() does
Jeroen Demeyer
report at bugs.python.org
Fri Jun 7 09:56:45 EDT 2019
Jeroen Demeyer <J.Demeyer at UGent.be> added the comment:
> What matters is the __mro__ attribute of the first argument. It matters
because that is how the MRO actually is searched.
I'm sorry to say that you're wrong here. super() looks at the MRO of the type of the object (the second argument) (*). It has to do that in order to support diamonds. Consider a diamond like
D
/ \
B C
\ /
A
(with A as common base class). Now super(B, D()).attr will look in the MRO of D (which is D, B, C, A) and therefore delegate to C.attr. In this case, C does not even appear in the MRO of B.
(*) To be pedantic: in the special case that the second argument is a type itself, it looks at the MRO of the second argument.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37176>
_______________________________________
More information about the docs
mailing list