Method resolution order and cooperative super()

Intermediate Python OOP Inheritance
Created by Pavel · 07.03.2026 at 19:57 UTC · 3 completed

Multiple inheritance forces a single, deterministic rule for which parent implementation runs when several paths meet. Python's MRO is that rule; ClassName.__mro__ shows the lookup tuple, and super() follows it so cooperative __init__ chains do not call Base twice in the diamond pattern.

In practice you log or trace construction when debugging framework code. The edge case is assuming super() means “call the parent” literally—it means “call the next class in the MRO,” which can be a sibling branch before the common base.

University approvals: 0
Tasks
Question 1

Which attribute shows the inheritance search order of a class?

Hint

It's a tuple of classes

Question 2

Implement the diamond with cooperative super() exactly as specified (names must match).

  • Base.__init__ sets self.log = ["Base"].
  • Left(Base).__init__ calls super().__init__() then self.log.append("Left").
  • Right(Base).__init__ calls super().__init__() then self.log.append("Right").
  • Diamond(Left, Right).__init__ calls super().__init__() then self.log.append("Diamond").
  • After d = Diamond(), assert d.log equals ['Base', 'Right', 'Left', 'Diamond'] (CPython 3 ordering).

Submit the full script. Tests use expression mode on your globals after execution.

Hint

Use super() in every init; do not call Base.init directly.

Starter code is prefilled; replace TODO blocks with your solution.
2 test cases will be used for grading
Run checks runtime behavior only. Final correctness is evaluated when you submit.
Card Info
  • Topic: Python OOP Inheritance
  • Difficulty: Intermediate
  • Completed: 3 users
Creator
Pavel
Pavel