What this Python equality-method interview question tests
This medium-difficulty Python question probes your understanding of how the __eq__ dunder method works and the subtle ways it interacts with object identity, method resolution, and return values. It's the kind of question that reveals whether a candidate has only read Python documentation or has actually debugged real code.
To solve it, you need to trace through what happens when equality is invoked on objects with custom implementations: which method gets called, in what order, what does it return, and how does Python interpret that return value. Edge cases around implicit fallbacks and type mismatches are common sources of surprises.
- Dunder method dispatch and method resolution order (MRO)
- Truthiness and how Python coerces return values in boolean contexts
- Symmetry and reflexivity of equality comparisons
- Default behaviour when
__eq__ is not defined