_structures.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. import typing
  5. @typing.final
  6. class InfinityType:
  7. __slots__ = ()
  8. def __repr__(self) -> str:
  9. return "Infinity"
  10. def __hash__(self) -> int:
  11. return hash(repr(self))
  12. def __lt__(self, other: object) -> bool:
  13. return False
  14. def __le__(self, other: object) -> bool:
  15. return False
  16. def __eq__(self, other: object) -> bool:
  17. return isinstance(other, self.__class__)
  18. def __gt__(self, other: object) -> bool:
  19. return True
  20. def __ge__(self, other: object) -> bool:
  21. return True
  22. def __neg__(self: object) -> "NegativeInfinityType":
  23. return NegativeInfinity
  24. Infinity = InfinityType()
  25. @typing.final
  26. class NegativeInfinityType:
  27. __slots__ = ()
  28. def __repr__(self) -> str:
  29. return "-Infinity"
  30. def __hash__(self) -> int:
  31. return hash(repr(self))
  32. def __lt__(self, other: object) -> bool:
  33. return True
  34. def __le__(self, other: object) -> bool:
  35. return True
  36. def __eq__(self, other: object) -> bool:
  37. return isinstance(other, self.__class__)
  38. def __gt__(self, other: object) -> bool:
  39. return False
  40. def __ge__(self, other: object) -> bool:
  41. return False
  42. def __neg__(self: object) -> InfinityType:
  43. return Infinity
  44. NegativeInfinity = NegativeInfinityType()