warnings.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. """LangGraph specific warnings."""
  2. from __future__ import annotations
  3. __all__ = (
  4. "LangGraphDeprecationWarning",
  5. "LangGraphDeprecatedSinceV05",
  6. "LangGraphDeprecatedSinceV10",
  7. )
  8. class LangGraphDeprecationWarning(DeprecationWarning):
  9. """A LangGraph specific deprecation warning.
  10. Attributes:
  11. message: Description of the warning.
  12. since: LangGraph version in which the deprecation was introduced.
  13. expected_removal: LangGraph version in what the corresponding functionality expected to be removed.
  14. Inspired by the Pydantic `PydanticDeprecationWarning` class, which sets a great standard
  15. for deprecation warnings with clear versioning information.
  16. """
  17. message: str
  18. since: tuple[int, int]
  19. expected_removal: tuple[int, int]
  20. def __init__(
  21. self,
  22. message: str,
  23. *args: object,
  24. since: tuple[int, int],
  25. expected_removal: tuple[int, int] | None = None,
  26. ) -> None:
  27. super().__init__(message, *args)
  28. self.message = message.rstrip(".")
  29. self.since = since
  30. self.expected_removal = (
  31. expected_removal if expected_removal is not None else (since[0] + 1, 0)
  32. )
  33. def __str__(self) -> str:
  34. message = (
  35. f"{self.message}. Deprecated in LangGraph V{self.since[0]}.{self.since[1]}"
  36. f" to be removed in V{self.expected_removal[0]}.{self.expected_removal[1]}."
  37. )
  38. return message
  39. class LangGraphDeprecatedSinceV05(LangGraphDeprecationWarning):
  40. """A specific `LangGraphDeprecationWarning` subclass defining functionality deprecated since LangGraph v0.5.0"""
  41. def __init__(self, message: str, *args: object) -> None:
  42. super().__init__(message, *args, since=(0, 5), expected_removal=(2, 0))
  43. class LangGraphDeprecatedSinceV10(LangGraphDeprecationWarning):
  44. """A specific `LangGraphDeprecationWarning` subclass defining functionality deprecated since LangGraph v1.0.0"""
  45. def __init__(self, message: str, *args: object) -> None:
  46. super().__init__(message, *args, since=(1, 0), expected_removal=(2, 0))