โ† eval6_submission

fastapi_14605

failed WRONG_FIX UNSUBMITTED wrong_fix_unsubmitted(budget) ยท 30 tool calls ยท 305 s ยท fastapi/fastapi

Task input

๐Ÿ”Š Add a custom `FastAPIDeprecationWarning`

๐Ÿ”Š Add a custom `FastAPIDeprecationWarning` and use it for deprecated logic, like Pydantic v1 models.

Motivated by: https://sethmlarson.dev/deprecations-via-warnings-dont-work-for-python-libraries

Tool calls (30)

#ToolArgumentsResult
1run_command
{
 "command": "grep -rn \"DeprecationWarning\" fastapi | head -20"
}
{"status": "ok", "stdout": "fastapi/dependencies/utils.py:330: category=DeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:66: category=DeprecationWarning,
full
{"status": "ok", "stdout": "fastapi/dependencies/utils.py:330:                category=DeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:66:                category=DeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:96:                category=DeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:506:                category=DeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:536:                category=DeprecationWarning,\nfastapi/routing.py:643:                    category=DeprecationWarning,\nfastapi/routing.py:683:                        category=DeprecationWarning,\nfastapi/utils.py:200:        DeprecationWarning,\nfastapi/params.py:78:                category=DeprecationWarning,\nfastapi/params.py:108:                category=DeprecationWarning,\nfastapi/params.py:533:                category=DeprecationWarning,\nfastapi/params.py:563:                category=DeprecationWarning,\nfastapi/openapi/utils.py:220:        DeprecationWarning,\n", "stderr": "", "exit_code": 0}
2run_command
{
 "command": "ls fastapi/__init__.py"
}
{"status": "ok", "stdout": "fastapi/__init__.py\n", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "fastapi/__init__.py\n", "stderr": "", "exit_code": 0}
3read_file
{
 "filepath": "fastapi/__init__.py"
}
{"status": "ok", "filepath": "fastapi/__init__.py", "content": "\"\"\"FastAPI framework, high performance, easy to learn, fast to code, ready for production\"\"
full
{"status": "ok", "filepath": "fastapi/__init__.py", "content": "\"\"\"FastAPI framework, high performance, easy to learn, fast to code, ready for production\"\"\"\n\n__version__ = \"0.127.0\"\n\nfrom starlette import status as status\n\nfrom .applications import FastAPI as FastAPI\nfrom .background import BackgroundTasks as BackgroundTasks\nfrom .datastructures import UploadFile as UploadFile\nfrom .exceptions import HTTPException as HTTPException\nfrom .exceptions import WebSocketException as WebSocketException\nfrom .param_functions import Body as Body\nfrom .param_functions import Cookie as Cookie\nfrom .param_functions import Depends as Depends\nfrom .param_functions import File as File\nfrom .param_functions import Form as Form\nfrom .param_functions import Header as Header\nfrom .param_functions import Path as Path\nfrom .param_functions import Query as Query\nfrom .param_functions import Security as Security\nfrom .requests import Request as Request\nfrom .responses import Response as Response\nfrom .routing import APIRouter as APIRouter\nfrom .websockets import WebSocket as WebSocket\nfrom .websockets import WebSocketDisconnect as WebSocketDisconnect", "start_line": 1, "end_line": 25, "total_lines": 25, "is_truncated": false}
4run_command
{
 "command": "grep -rn \"class \" fastapi/exceptions.py"
}
{"status": "ok", "stdout": "10:class EndpointContext(TypedDict, total=False):\n17:class HTTPException(StarletteHTTPException):\n76:class WebSocketException(Star
full
{"status": "ok", "stdout": "10:class EndpointContext(TypedDict, total=False):\n17:class HTTPException(StarletteHTTPException):\n76:class WebSocketException(StarletteWebSocketException):\n151:class FastAPIError(RuntimeError):\n157:class DependencyScopeError(FastAPIError):\n164:class ValidationException(Exception):\n202:class RequestValidationError(ValidationException):\n214:class WebSocketRequestValidationError(ValidationException):\n224:class ResponseValidationError(ValidationException):\n", "stderr": "", "exit_code": 0}
5read_file
{
 "filepath": "fastapi/exceptions.py",
 "start_line": "150",
 "end_line": "230"
}
{"status": "error", "error_type": "FileReadError", "error_message": "'>' not supported between instances of 'int' and 'str'"}
full
{"status": "error", "error_type": "FileReadError", "error_message": "'>' not supported between instances of 'int' and 'str'"}
6read_file
{
 "filepath": "fastapi/exceptions.py"
}
{"status": "ok", "filepath": "fastapi/exceptions.py", "content": "from collections.abc import Sequence\nfrom typing import Annotated, Any, Optional, TypedDict,
full
{"status": "ok", "filepath": "fastapi/exceptions.py", "content": "from collections.abc import Sequence\nfrom typing import Annotated, Any, Optional, TypedDict, Union\n\nfrom annotated_doc import Doc\nfrom pydantic import BaseModel, create_model\nfrom starlette.exceptions import HTTPException as StarletteHTTPException\nfrom starlette.exceptions import WebSocketException as StarletteWebSocketException\n\n\nclass EndpointContext(TypedDict, total=False):\n    function: str\n    path: str\n    file: str\n    line: int\n\n\nclass HTTPException(StarletteHTTPException):\n    \"\"\"\n    An HTTP exception you can raise in your own code to show errors to the client.\n\n    This is for client errors, invalid authentication, invalid data, etc. Not for server\n    errors in your code.\n\n    Read more about it in the\n    [FastAPI docs for Handling Errors](https://fastapi.tiangolo.com/tutorial/handling-errors/).\n\n    ## Example\n\n    ```python\n    from fastapi import FastAPI, HTTPException\n\n    app = FastAPI()\n\n    items = {\"foo\": \"The Foo Wrestlers\"}\n\n\n    @app.get(\"/items/{item_id}\")\n    async def read_item(item_id: str):\n        if item_id not in items:\n            raise HTTPException(status_code=404, detail=\"Item not found\")\n        return {\"item\": items[item_id]}\n    ```\n    \"\"\"\n\n    def __init__(\n        self,\n        status_code: Annotated[\n            int,\n            Doc(\n                \"\"\"\n                HTTP status code to send to the client.\n                \"\"\"\n            ),\n        ],\n        detail: Annotated[\n            Any,\n            Doc(\n                \"\"\"\n                Any data to be sent to the client in the `detail` key of the JSON\n                response.\n                \"\"\"\n            ),\n        ] = None,\n        headers: Annotated[\n            Optional[dict[str, str]],\n            Doc(\n                \"\"\"\n                Any headers to send to the client in the response.\n    
7read_file
{
 "filepath": "fastapi/exceptions.py",
 "start_line": "151"
}
{"status": "error", "error_type": "FileReadError", "error_message": "'>' not supported between instances of 'int' and 'str'"}
full
{"status": "error", "error_type": "FileReadError", "error_message": "'>' not supported between instances of 'int' and 'str'"}
8run_command
{
 "command": "tail -n 100 fastapi/exceptions.py"
}
{"status": "ok", "stdout": "\n It is UTF-8-encoded data. The interpretation of the reason is up to the\n application, it is not specified by the WebSocket speci
full
{"status": "ok", "stdout": "\n                It is UTF-8-encoded data. The interpretation of the reason is up to the\n                application, it is not specified by the WebSocket specification.\n\n                It could contain text that could be human-readable or interpretable\n                by the client code, etc.\n                \"\"\"\n            ),\n        ] = None,\n    ) -> None:\n        super().__init__(code=code, reason=reason)\n\n\nRequestErrorModel: type[BaseModel] = create_model(\"Request\")\nWebSocketErrorModel: type[BaseModel] = create_model(\"WebSocket\")\n\n\nclass FastAPIError(RuntimeError):\n    \"\"\"\n    A generic, FastAPI-specific error.\n    \"\"\"\n\n\nclass DependencyScopeError(FastAPIError):\n    \"\"\"\n    A dependency declared that it depends on another dependency with an invalid\n    (narrower) scope.\n    \"\"\"\n\n\nclass ValidationException(Exception):\n    def __init__(\n        self,\n        errors: Sequence[Any],\n        *,\n        endpoint_ctx: Optional[EndpointContext] = None,\n    ) -> None:\n        self._errors = errors\n        self.endpoint_ctx = endpoint_ctx\n\n        ctx = endpoint_ctx or {}\n        self.endpoint_function = ctx.get(\"function\")\n        self.endpoint_path = ctx.get(\"path\")\n        self.endpoint_file = ctx.get(\"file\")\n        self.endpoint_line = ctx.get(\"line\")\n\n    def errors(self) -> Sequence[Any]:\n        return self._errors\n\n    def _format_endpoint_context(self) -> str:\n        if not (self.endpoint_file and self.endpoint_line and self.endpoint_function):\n            if self.endpoint_path:\n                return f\"\\n  Endpoint: {self.endpoint_path}\"\n            return \"\"\n\n        context = f'\\n  File \"{self.endpoint_file}\", line {self.endpoint_line}, in {self.endpoint_function}'\n        if self.endpoint_path:\n            context += f\"\\n    {self.endpoint_path}\"\n        return context\n\n    def __str__(self) -> str:\n        message = f\"{len(self
9edit_file
{
 "filepath": "fastapi/.py",
 "new_string": "class FastAPIError(RuntimeError):\n    \"\"\"\n    A generic, FastAPI-specific error.\n    \"\"\"\n\n\nclass FastAPIDeprecationWarning(DeprecationWarning):\n    \"\"\"\n    A FastAPI-specific deprecation warning.\n    \"\"\"\n\n\nclass DependencyScopeError(FastAPIError):\n",
 "old_string": "class FastAPIError(RuntimeError):\n    \"\"\"\n    A generic, FastAPI-specific error.\n    \"\"\"\n\n\nclass DependencyScopeError(FastAPIError):\n"
}
{"status": "error", "error_type": "FileEditError", "error_message": "File 'fastapi/.py' not found in workspace."}
full
{"status": "error", "error_type": "FileEditError", "error_message": "File 'fastapi/.py' not found in workspace."}
10edit_file
{
 "filepath": "fastapi/exceptions.py",
 "new_string": "class FastAPIError(RuntimeError):\n    \"\"\"\n    A generic, FastAPI-specific error.\n    \"\"\"\n\n\nclass FastAPIDeprecationWarning(DeprecationWarning):\n    \"\"\"\n    A FastAPI-specific deprecation warning.\n    \"\"\"\n\n\nclass DependencyScopeError(FastAPIError):\n",
 "old_string": "class FastAPIError(RuntimeError):\n    \"\"\"\n    A generic, FastAPI-specific error.\n    \"\"\"\n\n\nclass DependencyScopeError(FastAPIError):\n"
}
{"status": "ok", "filepath": "fastapi/exceptions.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/exceptions.py\n+++ b/fastapi/exceptions.py\n
full
{"status": "ok", "filepath": "fastapi/exceptions.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/exceptions.py\n+++ b/fastapi/exceptions.py\n@@ -154,6 +154,12 @@\n     \"\"\"\n \n \n+class FastAPIDeprecationWarning(DeprecationWarning):\n+    \"\"\"\n+    A FastAPI-specific deprecation warning.\n+    \"\"\"\n+\n+\n class DependencyScopeError(FastAPIError):\n     \"\"\"\n     A dependency declared that it depends on another dependency with an invalid\n", "is_truncated": false}
11run_command
{
 "command": "grep -rn \"category=DeprecationWarning\" fastapi | head -20"
}
{"status": "ok", "stdout": "fastapi/dependencies/utils.py:330: category=DeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:66: category=DeprecationWarning,
full
{"status": "ok", "stdout": "fastapi/dependencies/utils.py:330:                category=DeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:66:                category=DeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:96:                category=DeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:506:                category=DeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:536:                category=DeprecationWarning,\nfastapi/routing.py:643:                    category=DeprecationWarning,\nfastapi/routing.py:683:                        category=DeprecationWarning,\nfastapi/params.py:78:                category=DeprecationWarning,\nfastapi/params.py:108:                category=DeprecationWarning,\nfastapi/params.py:533:                category=DeprecationWarning,\nfastapi/params.py:563:                category=DeprecationWarning,\n", "stderr": "", "exit_code": 0}
12read_file
{
 "filepath": "fastapi/temp_pydantic_v1_params.py"
}
{"status": "ok", "filepath": "fastapi/temp_pydantic_v1_params.py", "content": "import warnings\nfrom typing import Annotated, Any, Callable, Optional, Union\n\n
full
{"status": "ok", "filepath": "fastapi/temp_pydantic_v1_params.py", "content": "import warnings\nfrom typing import Annotated, Any, Callable, Optional, Union\n\nfrom fastapi.openapi.models import Example\nfrom fastapi.params import ParamTypes\nfrom typing_extensions import deprecated\n\nfrom ._compat.may_v1 import FieldInfo, Undefined\n\n_Unset: Any = Undefined\n\n\nclass Param(FieldInfo):\n    in_: ParamTypes\n\n    def __init__(\n        self,\n        default: Any = Undefined,\n        *,\n        default_factory: Union[Callable[[], Any], None] = _Unset,\n        annotation: Optional[Any] = None,\n        alias: Optional[str] = None,\n        alias_priority: Union[int, None] = _Unset,\n        # TODO: update when deprecating Pydantic v1, import these types\n        # validation_alias: str | AliasPath | AliasChoices | None\n        validation_alias: Union[str, None] = None,\n        serialization_alias: Union[str, None] = None,\n        title: Optional[str] = None,\n        description: Optional[str] = None,\n        gt: Optional[float] = None,\n        ge: Optional[float] = None,\n        lt: Optional[float] = None,\n        le: Optional[float] = None,\n        min_length: Optional[int] = None,\n        max_length: Optional[int] = None,\n        pattern: Optional[str] = None,\n        regex: Annotated[\n            Optional[str],\n            deprecated(\n                \"Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead.\"\n            ),\n        ] = None,\n        discriminator: Union[str, None] = None,\n        strict: Union[bool, None] = _Unset,\n        multiple_of: Union[float, None] = _Unset,\n        allow_inf_nan: Union[bool, None] = _Unset,\n        max_digits: Union[int, None] = _Unset,\n        decimal_places: Union[int, None] = _Unset,\n        examples: Optional[list[Any]] = None,\n        example: Annotated[\n            Optional[Any],\n            deprecated(\n                \"Deprecated in OpenAPI 3.1.0 that now uses JSON Sch
13edit_file
{
 "filepath": "fastapi/temp_pydantic_v1_params.py",
 "new_string": "import warnings\nfrom typing import Annotated, Any, Callable, Optional, Union\n\nfrom fastapi.exceptions import FastAPIDeprecationWarning\nfrom fastapi.openapi.models import Example\nfrom fastapi.params import ParamTypes\n",
 "old_string": "import warnings\nfrom typing import Annotated, Any, Callable, Optional, Union\n\nfrom fastapi.openapi.models import Example\nfrom fastapi.params import ParamTypes\n"
}
{"status": "ok", "filepath": "fastapi/temp_pydantic_v1_params.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/temp_pydantic_v1_params.py\n+++
full
{"status": "ok", "filepath": "fastapi/temp_pydantic_v1_params.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/temp_pydantic_v1_params.py\n+++ b/fastapi/temp_pydantic_v1_params.py\n@@ -1,6 +1,7 @@\n import warnings\n from typing import Annotated, Any, Callable, Optional, Union\n \n+from fastapi.exceptions import FastAPIDeprecationWarning\n from fastapi.openapi.models import Example\n from fastapi.params import ParamTypes\n from typing_extensions import deprecated\n", "is_truncated": false}
14edit_file
{
 "filepath": "fastapi/temp_pydantic_v1_params.py",
 "new_string": "        if example is not _Unset:\n            warnings.warn(\n                \"`example` has been deprecated, please use `examples` instead\",\n                category=FastAPIDeprecationWarning,\n                stacklevel=4,\n            )\n        self.example = example\n",
 "old_string": "        if example is not _Unset:\n            warnings.warn(\n                \"`example` has been deprecated, please use `examples` instead\",\n                category=DeprecationWarning,\n                stacklevel=4,\n            )\n        self.example = example\n"
}
{"status": "error", "error_type": "FileEditError", "error_message": "Target string occurs 2 times in fastapi/temp_pydantic_v1_params.py. Please provide more sur
full
{"status": "error", "error_type": "FileEditError", "error_message": "Target string occurs 2 times in fastapi/temp_pydantic_v1_params.py. Please provide more surrounding context."}
15edit_file
{
 "filepath": "fastapi/temp_pydantic_v1_params.py",
 "new_string": "        if example is not _Unset:\n            warnings.warn(\n                \"`example` has been deprecated, please use `examples` instead\",\n                category=FastAPIDeprecationWarning,\n                stacklevel=4,\n            )\n        self.example = example\n        self.include_in_schema = include_in_schema\n",
 "old_string": "        if example is not _Unset:\n            warnings.warn(\n                \"`example` has been deprecated, please use `examples` instead\",\n                category=DeprecationWarning,\n                stacklevel=4,\n            )\n        self.example = example\n        self.include_in_schema = include_in_schema\n"
}
{"status": "error", "error_type": "FileEditError", "error_message": "Target string occurs 2 times in fastapi/temp_pydantic_v1_params.py. Please provide more sur
full
{"status": "error", "error_type": "FileEditError", "error_message": "Target string occurs 2 times in fastapi/temp_pydantic_v1_params.py. Please provide more surrounding context."}
16read_file
{
 "filepath": "fastapi/temp_pydantic_v1_params.py",
 "start_line": "60",
 "end_line": "100"
}
{"status": "error", "error_type": "FileReadError", "error_message": "'>' not supported between instances of 'int' and 'str'"}
full
{"status": "error", "error_type": "FileReadError", "error_message": "'>' not supported between instances of 'int' and 'str'"}
17run_command
{
 "command": "grep -n \"category=DeprecationWarning\" fastapi/temp_pydantic_v1_params.py"
}
{"status": "ok", "stdout": "67: category=DeprecationWarning,\n97: category=DeprecationWarning,\n507: category=DeprecationWarning,\n537: category=DeprecationWarn
full
{"status": "ok", "stdout": "67:                category=DeprecationWarning,\n97:                category=DeprecationWarning,\n507:                category=DeprecationWarning,\n537:                category=DeprecationWarning,\n", "stderr": "", "exit_code": 0}
18read_file
{
 "filepath": "fastapi/temp_pydantic_v1_params.py",
 "start_line": "60",
 "end_line": "75"
}
{"status": "error", "error_type": "FileReadError", "error_message": "'>' not supported between instances of 'int' and 'str'"}
full
{"status": "error", "error_type": "FileReadError", "error_message": "'>' not supported between instances of 'int' and 'str'"}
19run_command
{
 "command": "sed -n '60,75p' fastapi/temp_pydantic_v1_params.py"
}
{"status": "ok", "stdout": " include_in_schema: bool = True,\n json_schema_extra: Union[dict[str, Any], None] = None,\n **extra: Any,\n ):\n if example is not _
full
{"status": "ok", "stdout": "        include_in_schema: bool = True,\n        json_schema_extra: Union[dict[str, Any], None] = None,\n        **extra: Any,\n    ):\n        if example is not _Unset:\n            warnings.warn(\n                \"`example` has been deprecated, please use `examples` instead\",\n                category=DeprecationWarning,\n                stacklevel=4,\n            )\n        self.example = example\n        self.include_in_schema = include_in_schema\n        self.openapi_examples = openapi_examples\n        kwargs = dict(\n            default=default,\n            default_factory=default_factory,\n", "stderr": "", "exit_code": 0}
20edit_file
{
 "filepath": "fastapi/temp_pydantic_v1_params.py",
 "new_string": "        if example is not _Unset:\n            warnings.warn(\n                \"`example` has been deprecated, please use `examples` instead\",\n                category=FastAPIDeprecationWarning,\n                stacklevel=4,\n            )\n        self.example = example\n",
 "old_string": "        if example is not _Unset:\n            warnings.warn(\n                \"`example` has been deprecated, please use `examples` instead\",\n                category=DeprecationWarning,\n                stacklevel=4,\n            )\n        self.example = example\n"
}
{"status": "error", "error_type": "FileEditError", "error_message": "Target string occurs 2 times in fastapi/temp_pydantic_v1_params.py. Please provide more sur
full
{"status": "error", "error_type": "FileEditError", "error_message": "Target string occurs 2 times in fastapi/temp_pydantic_v1_params.py. Please provide more surrounding context."}
21run_command
{
 "command": "sed -n '90,105p' fastapi/temp_pydantic_v1_params.py"
}
{"status": "ok", "stdout": " **extra,\n )\n if examples is not None:\n kwargs[\"examples\"] = examples\n if regex is not None:\n warnings.warn(\n \"`regex` has
full
{"status": "ok", "stdout": "            **extra,\n        )\n        if examples is not None:\n            kwargs[\"examples\"] = examples\n        if regex is not None:\n            warnings.warn(\n                \"`regex` has been deprecated, please use `pattern` instead\",\n                category=DeprecationWarning,\n                stacklevel=4,\n            )\n        current_json_schema_extra = json_schema_extra or extra\n        kwargs[\"deprecated\"] = deprecated\n        kwargs[\"regex\"] = pattern or regex\n        kwargs.update(**current_json_schema_extra)\n        use_kwargs = {k: v for k, v in kwargs.items() if v is not _Unset}\n\n", "stderr": "", "exit_code": 0}
22edit_file
{
 "filepath": "fastapi/temp_pydantic_v1_params.py",
 "new_string": "        if regex is not None:\n            warnings.warn(\n                \"`regex` has been deprecated, please use `pattern` instead\",\n                category=FastAPIDeprecationWarning,\n                stacklevel=4,\n            )\n        current_json_schema_extra = json_schema_extra or extra\n",
 "old_string": "        if regex is not None:\n            warnings.warn(\n                \"`regex` has been deprecated, please use `pattern` instead\",\n                category=DeprecationWarning,\n                stacklevel=4,\n            )\n        current_json_schema_extra = json_schema_extra or extra\n"
}
{"status": "error", "error_type": "FileEditError", "error_message": "Target string occurs 2 times in fastapi/temp_pydantic_v1_params.py. Please provide more sur
full
{"status": "error", "error_type": "FileEditError", "error_message": "Target string occurs 2 times in fastapi/temp_pydantic_v1_params.py. Please provide more surrounding context."}
23run_command
{
 "command": "sed -n '500,515p' fastapi/temp_pydantic_v1_params.py"
}
{"status": "ok", "stdout": " **extra: Any,\n ):\n self.embed = embed\n self.media_type = media_type\n if example is not _Unset:\n warnings.warn(\n \"`example` h
full
{"status": "ok", "stdout": "        **extra: Any,\n    ):\n        self.embed = embed\n        self.media_type = media_type\n        if example is not _Unset:\n            warnings.warn(\n                \"`example` has been deprecated, please use `examples` instead\",\n                category=DeprecationWarning,\n                stacklevel=4,\n            )\n        self.example = example\n        self.include_in_schema = include_in_schema\n        self.openapi_examples = openapi_examples\n        kwargs = dict(\n            default=default,\n            default_factory=default_factory,\n", "stderr": "", "exit_code": 0}
24run_command
{
 "command": "sed -n '530,545p' fastapi/temp_pydantic_v1_params.py"
}
{"status": "ok", "stdout": " **extra,\n )\n if examples is not None:\n kwargs[\"examples\"] = examples\n if regex is not None:\n warnings.warn(\n \"`regex` has
full
{"status": "ok", "stdout": "            **extra,\n        )\n        if examples is not None:\n            kwargs[\"examples\"] = examples\n        if regex is not None:\n            warnings.warn(\n                \"`regex` has been deprecated, please use `pattern` instead\",\n                category=DeprecationWarning,\n                stacklevel=4,\n            )\n        current_json_schema_extra = json_schema_extra or extra\n        kwargs[\"deprecated\"] = deprecated\n        kwargs[\"regex\"] = pattern or regex\n        kwargs.update(**current_json_schema_extra)\n\n        use_kwargs = {k: v for k, v in kwargs.items() if v is not _Unset}\n", "stderr": "", "exit_code": 0}
25edit_file
{
 "filepath": "fastapi/temp_pydantic_v1_params.py",
 "new_string": "        if example is not _Unset:\n            warnings.warn(\n                \"`example` has been deprecated, please use `examples` instead\",\n                category=FastAPIDeprecationWarning,\n                stacklevel=4,\n            )\n        self.example = example\n        self.include_in_schema = include_in_schema\n        self.openapi_examples = openapi_examples\n",
 "old_string": "        if example is not _Unset:\n            warnings.warn(\n                \"`example` has been deprecated, please use `examples` instead\",\n                category=DeprecationWarning,\n                stacklevel=4,\n            )\n        self.example = example\n        self.include_in_schema = include_in_schema\n        self.openapi_examples = openapi_examples\n"
}
{"status": "error", "error_type": "FileEditError", "error_message": "Target string occurs 2 times in fastapi/temp_pydantic_v1_params.py. Please provide more sur
full
{"status": "error", "error_type": "FileEditError", "error_message": "Target string occurs 2 times in fastapi/temp_pydantic_v1_params.py. Please provide more surrounding context."}
26run_command
{
 "command": "sed -n '60,80p' fastapi/temp_pydantic_v1_params.py"
}
{"status": "ok", "stdout": " include_in_schema: bool = True,\n json_schema_extra: Union[dict[str, Any], None] = None,\n **extra: Any,\n ):\n if example is not _
full
{"status": "ok", "stdout": "        include_in_schema: bool = True,\n        json_schema_extra: Union[dict[str, Any], None] = None,\n        **extra: Any,\n    ):\n        if example is not _Unset:\n            warnings.warn(\n                \"`example` has been deprecated, please use `examples` instead\",\n                category=DeprecationWarning,\n                stacklevel=4,\n            )\n        self.example = example\n        self.include_in_schema = include_in_schema\n        self.openapi_examples = openapi_examples\n        kwargs = dict(\n            default=default,\n            default_factory=default_factory,\n            alias=alias,\n            title=title,\n            description=description,\n            gt=gt,\n            ge=ge,\n", "stderr": "", "exit_code": 0}
27edit_file
{
 "filepath": "fastapi/temp_pydantic_v1_params.py",
 "new_string": "        if example is not _Unset:\n            warnings.warn(\n                \"`example` has been deprecated, please use `examples` instead\",\n                category=FastAPIDeprecationWarning,\n                stacklevel=4,\n            )\n        self.example = example\n        self.include_in_schema = include_in_schema\n        self.openapi_examples = openapi_examples\n        kwargs = dict(\n            default=default,\n            default_factory=default_factory,\n",
 "old_string": "        if example is not _Unset:\n            warnings.warn(\n                \"`example` has been deprecated, please use `examples` instead\",\n                category=DeprecationWarning,\n                stacklevel=4,\n            )\n        self.example = example\n        self.include_in_schema = include_in_schema\n        self.openapi_examples = openapi_examples\n        kwargs = dict(\n            default=default,\n            default_factory=default_factory,\n"
}
{"status": "error", "error_type": "FileEditError", "error_message": "Target string occurs 2 times in fastapi/temp_pydantic_v1_params.py. Please provide more sur
full
{"status": "error", "error_type": "FileEditError", "error_message": "Target string occurs 2 times in fastapi/temp_pydantic_v1_params.py. Please provide more surrounding context."}
28run_command
{
 "command": "sed -n '500,520p' fastapi/temp_pydantic_v1_params.py"
}
{"status": "ok", "stdout": " **extra: Any,\n ):\n self.embed = embed\n self.media_type = media_type\n if example is not _Unset:\n warnings.warn(\n \"`example` h
full
{"status": "ok", "stdout": "        **extra: Any,\n    ):\n        self.embed = embed\n        self.media_type = media_type\n        if example is not _Unset:\n            warnings.warn(\n                \"`example` has been deprecated, please use `examples` instead\",\n                category=DeprecationWarning,\n                stacklevel=4,\n            )\n        self.example = example\n        self.include_in_schema = include_in_schema\n        self.openapi_examples = openapi_examples\n        kwargs = dict(\n            default=default,\n            default_factory=default_factory,\n            alias=alias,\n            title=title,\n            description=description,\n            gt=gt,\n            ge=ge,\n", "stderr": "", "exit_code": 0}
29edit_file
{
 "filepath": "fastapi/temp_pydantic_v1_params.py",
 "new_string": "        self.embed = embed\n        self.media_type = media_type\n        if example is not _Unset:\n            warnings.warn(\n                \"`example` has been deprecated, please use `examples` instead\",\n                category=FastAPIDeprecationWarning,\n                stacklevel=4,\n            )\n        self.example = example\n",
 "old_string": "        self.embed = embed\n        self.media_type = media_type\n        if example is not _Unset:\n            warnings.warn(\n                \"`example` has been deprecated, please use `examples` instead\",\n                category=DeprecationWarning,\n                stacklevel=4,\n            )\n        self.example = example\n"
}
{"status": "ok", "filepath": "fastapi/temp_pydantic_v1_params.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/temp_pydantic_v1_params.py\n+++
full
{"status": "ok", "filepath": "fastapi/temp_pydantic_v1_params.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/temp_pydantic_v1_params.py\n+++ b/fastapi/temp_pydantic_v1_params.py\n@@ -504,7 +504,7 @@\n         if example is not _Unset:\n             warnings.warn(\n                 \"`example` has been deprecated, please use `examples` instead\",\n-                category=DeprecationWarning,\n+                category=FastAPIDeprecationWarning,\n                 stacklevel=4,\n             )\n         self.example = example\n", "is_truncated": false}
30edit_file
{
 "filepath": "fastapi/temp_pydantic_v1_params.py",
 "new_string": "        if example is not _Unset:\n            warnings.warn(\n                \"`example` has been deprecated, please use `examples` instead\",\n                category=FastAPIDeprecationWarning,\n                stacklevel=4,\n            )\n        self.example = example\n        self.include_in_schema = include_in_schema\n        self.openapi_examples = openapi_examples\n        kwargs = dict(\n            default=default,\n            default_factory=default_factory,\n            alias=alias,\n            title=title,\n            description=description,\n            gt=gt,\n            ge=ge,\n",
 "old_string": "        if example is not _Unset:\n            warnings.warn(\n                \"`example` has been deprecated, please use `examples` instead\",\n                category=DeprecationWarning,\n                stacklevel=4,\n            )\n        self.example = example\n        self.include_in_schema = include_in_schema\n        self.openapi_examples = openapi_examples\n        kwargs = dict(\n            default=default,\n            default_factory=default_factory,\n            alias=alias,\n            title=title,\n            description=description,\n            gt=gt,\n            ge=ge,\n"
}
{"status": "ok", "filepath": "fastapi/temp_pydantic_v1_params.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/temp_pydantic_v1_params.py\n+++
full
{"status": "ok", "filepath": "fastapi/temp_pydantic_v1_params.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/temp_pydantic_v1_params.py\n+++ b/fastapi/temp_pydantic_v1_params.py\n@@ -64,7 +64,7 @@\n         if example is not _Unset:\n             warnings.warn(\n                 \"`example` has been deprecated, please use `examples` instead\",\n-                category=DeprecationWarning,\n+                category=FastAPIDeprecationWarning,\n                 stacklevel=4,\n             )\n         self.example = example\n", "is_truncated": false}

Patch

diff --git a/fastapi/exceptions.py b/fastapi/exceptions.py
index 8e0c5590..05f8f216 100644
--- a/fastapi/exceptions.py
+++ b/fastapi/exceptions.py
@@ -154,6 +154,12 @@ class FastAPIError(RuntimeError):
     """
 
 
+class FastAPIDeprecationWarning(DeprecationWarning):
+    """
+    A FastAPI-specific deprecation warning.
+    """
+
+
 class DependencyScopeError(FastAPIError):
     """
     A dependency declared that it depends on another dependency with an invalid
diff --git a/fastapi/temp_pydantic_v1_params.py b/fastapi/temp_pydantic_v1_params.py
index 1bda0ea9..1a173a71 100644
--- a/fastapi/temp_pydantic_v1_params.py
+++ b/fastapi/temp_pydantic_v1_params.py
@@ -1,6 +1,7 @@
 import warnings
 from typing import Annotated, Any, Callable, Optional, Union
 
+from fastapi.exceptions import FastAPIDeprecationWarning
 from fastapi.openapi.models import Example
 from fastapi.params import ParamTypes
 from typing_extensions import deprecated
@@ -63,7 +64,7 @@ class Param(FieldInfo):
         if example is not _Unset:
             warnings.warn(
                 "`example` has been deprecated, please use `examples` instead",
-                category=DeprecationWarning,
+                category=FastAPIDeprecationWarning,
                 stacklevel=4,
             )
         self.example = example
@@ -503,7 +504,7 @@ class Body(FieldInfo):
         if example is not _Unset:
             warnings.warn(
                 "`example` has been deprecated, please use `examples` instead",
-                category=DeprecationWarning,
+                category=FastAPIDeprecationWarning,
                 stacklevel=4,
             )
         self.example = example

Test output

show
................................F
=================================== FAILURES ===================================
_____________________ test_query_regex_deprecation_warning _____________________

    def test_query_regex_deprecation_warning():
>       with pytest.warns(FastAPIDeprecationWarning, match="`regex` has been deprecated"):
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E       Failed: DID NOT WARN. No warnings of type (<class 'fastapi.exceptions.FastAPIDeprecationWarning'>,) were emitted.
E        Emitted warnings: [ DeprecationWarning('`regex` has been deprecated, please use `pattern` instead')].

tests/test_compat_params_v1.py:508: Failed
=============================== warnings summary ===============================
../../../../../../kaggle/tmp/envs/overlays/starlette-0.50.0-py3-none-any/starlette/testclient.py:45
  /kaggle/tmp/envs/overlays/starlette-0.50.0-py3-none-any/starlette/testclient.py:45: DeprecationWarning: The anyio.abc.BlockingPortal alias is deprecated, use anyio.from_thread.BlockingPortal instead.
    _PortalFactoryType = Callable[[], AbstractContextManager[anyio.abc.BlockingPortal]]

tests/test_compat_params_v1.py::test_query_regex_deprecation_warning
  /kaggle/tmp/envs/fastapi/lib/python3.13/site-packages/_pytest/python.py:167: DeprecationWarning: `regex` has been deprecated, please use `pattern` instead
    result = testfunction(**testargs)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
1 failed, 32 passed, 1 skipped, 2 warnings in 1.13s