@total_ordering class A(object): def __init__(self, value): self.value = value def __lt__(self, other): if not isinstance(other, A): return NotImplemented return self.value < other.value def __eq__(self, other): if not isinstance(other, A): return NotImplemented return self.value == other.value @total_ordering class C(object): def __init__(self, value): self.value = value def __lt__(self, other): if not isinstance(other, C): return NotImplemented return self.value < other.value def __eq__(self, other): if not isinstance(other, C): return NotImplemented return self.value == other.value # This works as expected: print(A(2)A(3)) # False # Comparing A and C, however, causes a stack overflow: print(A(2)