typing.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from __future__ import annotations
  2. from typing_extensions import TypeVar
  3. from langgraph._internal._typing import StateLike
  4. __all__ = (
  5. "StateT",
  6. "StateT_co",
  7. "StateT_contra",
  8. "InputT",
  9. "OutputT",
  10. "ContextT",
  11. )
  12. StateT = TypeVar("StateT", bound=StateLike)
  13. """Type variable used to represent the state in a graph."""
  14. StateT_co = TypeVar("StateT_co", bound=StateLike, covariant=True)
  15. StateT_contra = TypeVar("StateT_contra", bound=StateLike, contravariant=True)
  16. ContextT = TypeVar("ContextT", bound=StateLike | None, default=None)
  17. """Type variable used to represent graph run scoped context.
  18. Defaults to `None`.
  19. """
  20. ContextT_contra = TypeVar(
  21. "ContextT_contra", bound=StateLike | None, contravariant=True, default=None
  22. )
  23. InputT = TypeVar("InputT", bound=StateLike, default=StateT)
  24. """Type variable used to represent the input to a `StateGraph`.
  25. Defaults to `StateT`.
  26. """
  27. OutputT = TypeVar("OutputT", bound=StateLike, default=StateT)
  28. """Type variable used to represent the output of a `StateGraph`.
  29. Defaults to `StateT`.
  30. """
  31. NodeInputT = TypeVar("NodeInputT", bound=StateLike)
  32. """Type variable used to represent the input to a node."""
  33. NodeInputT_contra = TypeVar("NodeInputT_contra", bound=StateLike, contravariant=True)