from functools import total_ordering class C: def __lt__(self, other): return NotImplemented def __eq__(self, other): return self is other @total_ordering class D(C): pass if __name__ == '__main__': a, b = C(), C() c, d = D(), D() try: a < b except TypeError: print("raised TypeError as expected") try: c < d except TypeError: print("raised TypeError as expected")