super() appears not to work with multiple inheritance
This derives from this forum post.
class A:
def __init__(self):
print("A.__init__")
class B(A):
def __init__(self):
print("B.__init__")
super().__init__()
class C(A):
def __init__(self):
print("C.__init__")
super().__init__()
class D(B,C):
def __init__(self):
print("D.__init__")
super().__init__()
If you issue D() at the REPL you get:
>>> D()
D.__init__
B.__init__
A.__init__
<D object at aac31180>
whereas cPython gives:
>>> D()
D.__init__
B.__init__
C.__init__
A.__init__
<__main__.D object at 0x7f40ecd1a358>
>>>
A further issue with super() - with single inheritance - is this. Despite numerous successful uses I wrote one class where super() returned an empty string. Unfortunately any attempt to produce a test case failed. I appreciate that's a lousy bug report but I thought it worth mentioning if the code is being reviewed.
tests/cpydiff/core_class: Document issue with super in classmethod.
Summary
This documents an existing problem with the way super() is implemented that became evident while I was implementing __init_subclass__, where when used inside a classmethod it defers to the ancestor of the class object itself (i.e. type), rather than parent classes it inherits from.
This is probably an issue with super itself not treating the second argument differently when its a type in the way that CPython does.
Testing
I've verified this against CPython versions 3.8, 3.10, and 3.12.