[issue38262] Mixins - super calls in bases of multiple-inheritance with different parameters

Steven D'Aprano report at bugs.python.org
Tue Sep 24 09:07:58 EDT 2019


Steven D'Aprano <steve+python at pearwood.info> added the comment:

I'm not an expert on super and multiple inheritance, but let me see if I can explain what is going on. (Hopefully an expert will correct me if I get something wrong.)

1. The class C(A_With_Arg, B_With_Arg) is straight-forward: the super call inside A passes the True parameter to B, which passes it to object, which raises.

2. The class C(B_With_Arg, A_With_Arg) is the same, except B passes the parameter to A, which passes it to object, which raises.

3. The class C(A_With_Arg, B_Without_Arg) is also straight-forward: the super call inside A passes the True parameter to B, but B ignores it and passes nothing to object.

4. The class C(B_Without_Arg, A_With_Arg) is the tricky case. The super call inside B passes no arguments to A, so A gets the default value of False for its parameter. Since A's propagate parameter is False, it doesn't call super at all, object's __init__ method doesn't get called, and there's no exception.


I've added another version, mixin_tests2.py, which hopefully makes it a bit easier to see what is happening.

You said: "The 'super()' call propagates the call resolution by definition
to the next level".

I think this means that you expect that in class C(A, B), A.__init__ will call object.__init__, and B.__init__ will call object.__init__ as well. But that's not what happens. That's what Python 2 "classic classes" did, but it was buggy, because superclasses would be called *twice*.

Perhaps it will help to read this:

https://www.python.org/download/releases/2.3/mro/


So I believe that the behaviour you are seeing is correct, there is no error or bug. Do you agree? If so, we can close this issue. Otherwise, if you disagree and still believe this is a bug, please explain why you think it is a bug.

----------
Added file: https://bugs.python.org/file48623/mixin_tests2.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38262>
_______________________________________


More information about the Python-bugs-list mailing list