_compat.py 649 B

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