Skip to content

Commit

Permalink
♻️ Update internal checks to support Pydantic 2.10 (#12914)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiangolo authored Nov 12, 2024
1 parent f716490 commit 91a9293
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion fastapi/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@

# 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 = {
Expand Down
10 changes: 7 additions & 3 deletions fastapi/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
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

Expand Down Expand Up @@ -105,7 +109,7 @@ def __init__(
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
Expand Down Expand Up @@ -561,7 +565,7 @@ def __init__(
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
Expand Down

0 comments on commit 91a9293

Please sign in to comment.