Why is the presence of super().__init__()
in the base classes necessary for the super().__init__()
in the child class to run through both inheritance branches?
The code below illustrates what happens with and without super().__init__()
in the base classes:
import sys
#--------------------------------
class one():
def __init__(self):
super().__init__()
print("one")
class two():
def __init__(self):
super().__init__()
print("two")
class three(one,two):
def __init__(self):
super().__init__()
print("three")
#--------------------------------
class uno():
def __init__(self):
print("uno")
class dos():
def __init__(self):
print("dos")
class tres(uno,dos):
def __init__(self):
super().__init__()
print("tres")
print("python version")
print(sys.version)
print("---------------")
a = three()
print("---------------")
b = tres()
Output:
python version
3.8.12 (default, Aug 30 2021, 16:42:10)
[GCC 10.3.0]
---------------
two
one
three
---------------
uno
tres