CodexBloom - Programming Q&A Platform

implementing Inheritance and Method Resolution Order in Python 3.9 - TypeError when Calling Super()

👀 Views: 41 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-07
python inheritance method-resolution-order Python

I'm getting frustrated with I'm updating my dependencies and I'm working with a challenging scenario with method resolution order (MRO) in Python 3.9 that results in a `TypeError`. I have a class hierarchy that uses both inheritance and mixins, and when I try to call a method from the parent class, I'm getting an behavior. Here's a simplified version of my code: ```python class Base: def greet(self): return "Hello from Base" class Mixin: def greet(self): return "Hello from Mixin" class Child(Base, Mixin): def greet(self): # Trying to call greet from Base class return super().greet() child_instance = Child() print(child_instance.greet()) ``` When I run this code, I get the following behavior: ``` TypeError: greet() missing 1 required positional argument: 'self' ``` I have tried changing the order of inheritance in the `Child` class (i.e., `class Child(Mixin, Base):`), but I still encounter the same behavior. I also attempted explicitly calling the base method using `Base.greet(self)`, which gives me the same `TypeError`. Additionally, I verified that there are no conflicting method signatures in the classes. I am not sure how to correctly resolve the method call to the `Base` class without running into these errors. Any insights on why this is happening and how I might resolve it would be greatly appreciated! I appreciate any insights! I'm open to any suggestions.