_compat.py 612 B

123456789101112131415161718192021
  1. from typing import Any, Literal
  2. from pydantic import BaseModel
  3. from pydantic.version import VERSION as PYDANTIC_VERSION
  4. PYDANTIC_V2 = PYDANTIC_VERSION.startswith("2.")
  5. if PYDANTIC_V2:
  6. from pydantic_core import Url as Url
  7. def _model_dump(
  8. model: BaseModel, mode: Literal["json", "python"] = "json", **kwargs: Any
  9. ) -> Any:
  10. return model.model_dump(mode=mode, **kwargs)
  11. else:
  12. from pydantic import AnyUrl as Url # noqa: F401
  13. def _model_dump(
  14. model: BaseModel, mode: Literal["json", "python"] = "json", **kwargs: Any
  15. ) -> Any:
  16. return model.dict(**kwargs)