undefined.py 835 B

12345678910111213141516171819202122232425262728293031323334
  1. from typing import Any
  2. __all__ = ["Undefined", "UndefinedType"]
  3. class UndefinedType(ValueError):
  4. """Auxiliary class for creating the Undefined singleton."""
  5. def __repr__(self) -> str:
  6. return "Undefined"
  7. __str__ = __repr__
  8. def __hash__(self) -> int:
  9. return hash(UndefinedType)
  10. def __bool__(self) -> bool:
  11. return False
  12. def __eq__(self, other: Any) -> bool:
  13. return other is Undefined
  14. def __ne__(self, other: Any) -> bool:
  15. return not self == other
  16. # Used to indicate undefined or invalid values (like "undefined" in JavaScript):
  17. Undefined = UndefinedType()
  18. Undefined.__doc__ = """Symbol for undefined values
  19. This singleton object is used to describe undefined or invalid values.
  20. It can be used in places where you would use ``undefined`` in GraphQL.js.
  21. """