class A:
def __init__(self, arg):
print("hit A")
self.arg = 1
print("close:A")
return
class B(A):
def __init__(self, arg, arg1):
print("hit B")
super().__init__(arg)
self.arg1 = arg1
print("close B")
return
class D(A):
def __init__(self, arg, arg1):
print("hit D")
super().__init__(arg)
self.arg1 = 3
print("done D")
return
class C(D, B):
def __init__(self, arg, arg1):
print("hit C")
super().__init__(arg, arg1)
print("done C")
return
c = C(1,2)
Throws a TypeError when D calls A.init because of missing required positional argument: arg1.
I am aware of how to get around this situation but my question is: why does this happen? If you flip the ordering of D and B, the error gets thrown in B so it is happening regardless of order and has to be related to how D and B are written but just passing arg1 to A makes no sense (although that does it solve it). I am obviously not understanding something about super() or multiple inheritance in Python.
(I am never doing this again btw. This is based on some real-life code, I wrote this up using composition in another language, and am aware that whatever I did here wasn't a good idea.)