fork download
  1.  
  2. class LikeDate:
  3. def __eq__(self, other):
  4. if isinstance(other, LikeDate):
  5. return True
  6. else:
  7. return NotImplemented
  8. def __ge__(self, other):
  9. if isinstance(other, LikeDate):
  10. return True
  11. else:
  12. return NotImplemented
  13.  
  14. class LikeInt:
  15. def __eq__(self, other):
  16. if isinstance(other, LikeInt):
  17. return True
  18. else:
  19. return False
  20.  
  21. def __ge__(self, other):
  22. if isinstance(other, LikeInt):
  23. return True
  24. else:
  25. return NotImplemented
  26.  
  27. a = LikeDate()
  28. b = LikeInt()
  29. print(a == b) # False
  30. print(a == 0) # False, because int provides an __eq__ method that returns False
  31. print(a >= 0) # Error, because nether LikeDate nor int provides a definite comparison for __ge__
  32. print(a >= b) # Error, because neither objects provide a comparable __ge__
Runtime error #stdin #stdout #stderr 0.04s 9404KB
stdin
Standard input is empty
stdout
False
False
stderr
Traceback (most recent call last):
  File "./prog.py", line 31, in <module>
TypeError: unorderable types: LikeDate() >= int()