class Base():
def func(self):
print("Base")
class A(Base):
def func(self):
print("A runs func")
super().func()
print("A func done")
class B(Base):
def func(self):
print("B runs func")
super().func()
print("B func done")
class C(A, B):
def func(self):
print("C runs func")
super().func()
print("C func done")
c = C()
c.func()
# get MRO
print(c.__class__.__mro__)
I'm trying to understand the super() in python, and I have this piece of code. When both class A and B have super(). everything is nice, I have this output
C runs func
A runs func
B runs func
Base
B func done
A func done
C func done
(<class 'main.C'>, <class 'main.A'>, <class 'main.B'>, <class 'main.Base'>, <class 'object'>)
===
but when A's super() commented out, I get
C runs func
A runs func
A func done
C func done
MRO info always printed, which is fine
===
when only B's super() commented out, I get
C runs func
A runs func
B runs func
B func done
A func done
C func done
=== when both super() are gone, it's same as no super() in A. Is this happening because python only traces according to the MRO table, and stops where there's no super()? but print(c.class.mro) shows every class is executed. Why is it the class gets "executed" but func() is not executed?