_compat.py 641 B

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