From 1586ee9cd6642025117775b6474710e58903abe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sat, 20 Dec 2025 13:22:06 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Remove=20additional=20usages=20o?= =?UTF-8?q?f=20Pydantic=20v1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi/datastructures.py | 16 ---------------- fastapi/params.py | 11 ++--------- fastapi/temp_pydantic_v1_params.py | 11 ++--------- 3 files changed, 4 insertions(+), 34 deletions(-) diff --git a/fastapi/datastructures.py b/fastapi/datastructures.py index b38a326de..492cbfccc 100644 --- a/fastapi/datastructures.py +++ b/fastapi/datastructures.py @@ -1,4 +1,3 @@ -from collections.abc import Iterable from typing import ( Annotated, Any, @@ -135,27 +134,12 @@ class UploadFile(StarletteUploadFile): """ return await super().close() - @classmethod - def __get_validators__(cls: type["UploadFile"]) -> Iterable[Callable[..., Any]]: - yield cls.validate - - @classmethod - def validate(cls: type["UploadFile"], v: Any) -> Any: - if not isinstance(v, StarletteUploadFile): - raise ValueError(f"Expected UploadFile, received: {type(v)}") - return v - @classmethod def _validate(cls, __input_value: Any, _: Any) -> "UploadFile": if not isinstance(__input_value, StarletteUploadFile): raise ValueError(f"Expected UploadFile, received: {type(__input_value)}") return cast(UploadFile, __input_value) - # TODO: remove when deprecating Pydantic v1 - @classmethod - def __modify_schema__(cls, field_schema: dict[str, Any]) -> None: - field_schema.update({"type": "string", "format": "binary"}) - @classmethod def __get_pydantic_json_schema__( cls, core_schema: CoreSchema, handler: GetJsonSchemaHandler diff --git a/fastapi/params.py b/fastapi/params.py index 97d57a2a5..c776c4a59 100644 --- a/fastapi/params.py +++ b/fastapi/params.py @@ -9,7 +9,6 @@ from pydantic.fields import FieldInfo from typing_extensions import Literal, deprecated from ._compat import ( - PYDANTIC_VERSION_MINOR_TUPLE, Undefined, ) @@ -110,10 +109,7 @@ class Param(FieldInfo): # type: ignore[misc] stacklevel=4, ) current_json_schema_extra = json_schema_extra or extra - if PYDANTIC_VERSION_MINOR_TUPLE < (2, 7): - self.deprecated = deprecated - else: - kwargs["deprecated"] = deprecated + kwargs["deprecated"] = deprecated if serialization_alias in (_Unset, None) and isinstance(alias, str): serialization_alias = alias @@ -568,10 +564,7 @@ class Body(FieldInfo): # type: ignore[misc] stacklevel=4, ) current_json_schema_extra = json_schema_extra or extra - if PYDANTIC_VERSION_MINOR_TUPLE < (2, 7): - self.deprecated = deprecated - else: - kwargs["deprecated"] = deprecated + kwargs["deprecated"] = deprecated if serialization_alias in (_Unset, None) and isinstance(alias, str): serialization_alias = alias if validation_alias in (_Unset, None): diff --git a/fastapi/temp_pydantic_v1_params.py b/fastapi/temp_pydantic_v1_params.py index b6c804dc4..a01d4a2aa 100644 --- a/fastapi/temp_pydantic_v1_params.py +++ b/fastapi/temp_pydantic_v1_params.py @@ -6,7 +6,6 @@ from fastapi.params import ParamTypes from typing_extensions import deprecated from ._compat.may_v1 import FieldInfo, Undefined -from ._compat.shared import PYDANTIC_VERSION_MINOR_TUPLE _Unset: Any = Undefined @@ -98,10 +97,7 @@ class Param(FieldInfo): # type: ignore[misc] stacklevel=4, ) current_json_schema_extra = json_schema_extra or extra - if PYDANTIC_VERSION_MINOR_TUPLE < (2, 7): - self.deprecated = deprecated - else: - kwargs["deprecated"] = deprecated + kwargs["deprecated"] = deprecated kwargs["regex"] = pattern or regex kwargs.update(**current_json_schema_extra) use_kwargs = {k: v for k, v in kwargs.items() if v is not _Unset} @@ -541,10 +537,7 @@ class Body(FieldInfo): # type: ignore[misc] stacklevel=4, ) current_json_schema_extra = json_schema_extra or extra - if PYDANTIC_VERSION_MINOR_TUPLE < (2, 7): - self.deprecated = deprecated - else: - kwargs["deprecated"] = deprecated + kwargs["deprecated"] = deprecated kwargs["regex"] = pattern or regex kwargs.update(**current_json_schema_extra)