_structures.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # This file is dual licensed under the terms of the Apache License, Version
  2. # 2.0, and the BSD License. See the LICENSE file in the root of this repository
  3. # for complete details.
  4. class InfinityType:
  5. def __repr__(self) -> str:
  6. return "Infinity"
  7. def __hash__(self) -> int:
  8. return hash(repr(self))
  9. def __lt__(self, other: object) -> bool:
  10. return False
  11. def __le__(self, other: object) -> bool:
  12. return False
  13. def __eq__(self, other: object) -> bool:
  14. return isinstance(other, self.__class__)
  15. def __gt__(self, other: object) -> bool:
  16. return True
  17. def __ge__(self, other: object) -> bool:
  18. return True
  19. def __neg__(self: object) -> "NegativeInfinityType":
  20. return NegativeInfinity
  21. Infinity = InfinityType()
  22. class NegativeInfinityType:
  23. def __repr__(self) -> str:
  24. return "-Infinity"
  25. def __hash__(self) -> int:
  26. return hash(repr(self))
  27. def __lt__(self, other: object) -> bool:
  28. return True
  29. def __le__(self, other: object) -> bool:
  30. return True
  31. def __eq__(self, other: object) -> bool:
  32. return isinstance(other, self.__class__)
  33. def __gt__(self, other: object) -> bool:
  34. return False
  35. def __ge__(self, other: object) -> bool:
  36. return False
  37. def __neg__(self: object) -> InfinityType:
  38. return Infinity
  39. NegativeInfinity = NegativeInfinityType()