0

So I need some clarification on super() and how it searches MRO. I hear so many people say first it searches in the child class for the method and if not found moves to the next one in the MRO. Obviously I know it will call the method in the first parent class… but if I have a method in the child class that’s the same name how does it know to bypass that method and call the next one up. For instance my child class has a call() method and the parent class has a call() method. If it searches first in the child class why does it do this?

class A:

  def call():
    print(‘class A was called’)

class B(A):
  
  def call():
    print(‘class B was called’)

  def sup():
    super().call()
ShadowRanger
  • 143,180
  • 12
  • 188
  • 271
  • The two implicit arguments to `super` here are `B` and `self` (assuming the correct definition `def sup(self): ...`). Lookup uses the MRO of `type(self)`, but starts *after* `B`. That is, lookup proceeds according to `[A, object]`, not `[B, A, object]`. – chepner Jun 08 '23 at 13:10

0 Answers0