]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
♻️ Update internal checks to support Pydantic 2.10 (#12914)
authorSebastián Ramírez <tiangolo@gmail.com>
Tue, 12 Nov 2024 16:10:42 +0000 (17:10 +0100)
committerGitHub <noreply@github.com>
Tue, 12 Nov 2024 16:10:42 +0000 (17:10 +0100)
fastapi/_compat.py
fastapi/params.py

index 56c5d744e40baf69e2cc240714d96d11c20af3e0..2b4d3e725af0f288d4d7990cd8ac92ea11416aa4 100644 (file)
@@ -27,7 +27,8 @@ from typing_extensions import Annotated, Literal, get_args, get_origin
 
 # Reassign variable to make it reexported for mypy
 PYDANTIC_VERSION = P_VERSION
-PYDANTIC_V2 = PYDANTIC_VERSION.startswith("2.")
+PYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(".")[:2])
+PYDANTIC_V2 = PYDANTIC_VERSION_MINOR_TUPLE[0] == 2
 
 
 sequence_annotation_to_type = {
index 90ca7cb010e6c24dd689a5cf2119eba93d88446c..8f5601dd31e53804bb3c4de6e577d8612b79bcb1 100644 (file)
@@ -6,7 +6,11 @@ from fastapi.openapi.models import Example
 from pydantic.fields import FieldInfo
 from typing_extensions import Annotated, deprecated
 
-from ._compat import PYDANTIC_V2, PYDANTIC_VERSION, Undefined
+from ._compat import (
+    PYDANTIC_V2,
+    PYDANTIC_VERSION_MINOR_TUPLE,
+    Undefined,
+)
 
 _Unset: Any = Undefined
 
@@ -105,7 +109,7 @@ class Param(FieldInfo):
                 stacklevel=4,
             )
         current_json_schema_extra = json_schema_extra or extra
-        if PYDANTIC_VERSION < "2.7.0":
+        if PYDANTIC_VERSION_MINOR_TUPLE < (2, 7):
             self.deprecated = deprecated
         else:
             kwargs["deprecated"] = deprecated
@@ -561,7 +565,7 @@ class Body(FieldInfo):
                 stacklevel=4,
             )
         current_json_schema_extra = json_schema_extra or extra
-        if PYDANTIC_VERSION < "2.7.0":
+        if PYDANTIC_VERSION_MINOR_TUPLE < (2, 7):
             self.deprecated = deprecated
         else:
             kwargs["deprecated"] = deprecated