Newbie question on super()
: In the toy example below, I was surprised that the output is C
and not A
since J
in inherits foo
from A
. Here is the code:
class A:
def foo(self):
return 'A'
class C(A):
def foo(self):
return 'C'
class J(A):
pass
class E(J, C):
def f(self):
return super().foo()
def foo(self):
return 'E'
print(E().f())
J
inherits foo
from A
; the MRO of E is:
(<class '__main__.E'>, <class '__main__.J'>, <class '__main__.C'>, <class '__main__.A'>, <class 'object'>)
so how come 'A' isn't the return value? ie evaluation proceeds to C