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

Steven D'Aprano report at bugs.python.org
Tue Sep 24 20:17:23 EDT 2019


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

Apologies for the Python 2.7 incompatible syntax, I hadn't noticed that you had selected 2.7. But since 2.7 (and 3.8) are in feature freeze, any behavoural changes can only apply to 3.9 or later.

I'm afraid that you haven't explained why you think the code is buggy. Does the behaviour differ from the documented behaviour in any way?

"My basic assumption here is that the call routing by MRO should or even must not be intermixed with the actually passed call parameters."

I'm afraid I don't understand this.

"Remark: I assume, that the single call of "object.__init__()" is here intentional."

Of course it is intentional, as calling a superclass method twice is incorrect behaviour. You cannot expect that all superclass methods are idempotent. Obviously, in the case of ``object`` itself, there's no harm in calling __init__ twice but think about superclasses that have side-effects, or do expensive processing, and aren't idempotent. If you call them twice in the inheritance chain, bad things can happen.

Which is why languages that support multiple inheritance generally require that the MRO is linearized so that each superclass is called once and exactly once. That was the problem with Python 2 classic classes and fixing it was one of the motivations of introducing so-called "new style classes" and object.

See the link I provided in my previous comment, and also:

https://courses.cs.northwestern.edu/325/readings/inheritance.php

Unless you can explain how and why this behaviour differs from the documented behaviour, I'm going to close this as "Not a bug". If you want to argue that the C3 linearization algorithm is "wrong", you probably should take that to the Python-Dev mailing list. The argument by KISS is probably not going to be enough: it is more important for code to be *correct* than to be simple, and the simple multiple inheritance algorithm is demonstrably incorrect.

----------
versions: +Python 3.9 -Python 2.7, Python 3.6

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


More information about the Python-bugs-list mailing list