Skip to content

Commit 91a9293

Browse files
authored
♻️ Update internal checks to support Pydantic 2.10 (#12914)
1 parent f716490 commit 91a9293

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

fastapi/_compat.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727

2828
# Reassign variable to make it reexported for mypy
2929
PYDANTIC_VERSION = P_VERSION
30-
PYDANTIC_V2 = PYDANTIC_VERSION.startswith("2.")
30+
PYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(".")[:2])
31+
PYDANTIC_V2 = PYDANTIC_VERSION_MINOR_TUPLE[0] == 2
3132

3233

3334
sequence_annotation_to_type = {

fastapi/params.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
from pydantic.fields import FieldInfo
77
from typing_extensions import Annotated, deprecated
88

9-
from ._compat import PYDANTIC_V2, PYDANTIC_VERSION, Undefined
9+
from ._compat import (
10+
PYDANTIC_V2,
11+
PYDANTIC_VERSION_MINOR_TUPLE,
12+
Undefined,
13+
)
1014

1115
_Unset: Any = Undefined
1216

@@ -105,7 +109,7 @@ def __init__(
105109
stacklevel=4,
106110
)
107111
current_json_schema_extra = json_schema_extra or extra
108-
if PYDANTIC_VERSION < "2.7.0":
112+
if PYDANTIC_VERSION_MINOR_TUPLE < (2, 7):
109113
self.deprecated = deprecated
110114
else:
111115
kwargs["deprecated"] = deprecated
@@ -561,7 +565,7 @@ def __init__(
561565
stacklevel=4,
562566
)
563567
current_json_schema_extra = json_schema_extra or extra
564-
if PYDANTIC_VERSION < "2.7.0":
568+
if PYDANTIC_VERSION_MINOR_TUPLE < (2, 7):
565569
self.deprecated = deprecated
566570
else:
567571
kwargs["deprecated"] = deprecated

0 commit comments

Comments
 (0)