From ab997c582103c42e742992f3a139a927fab24e9b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 6 Nov 2025 18:55:32 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20[pre-commit.ci]=20Auto=20format?= =?UTF-8?q?=20from=20pre-commit.com=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi/exceptions.py | 2 ++ fastapi/routing.py | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/fastapi/exceptions.py b/fastapi/exceptions.py index 17e3202b8..9476fe9cb 100644 --- a/fastapi/exceptions.py +++ b/fastapi/exceptions.py @@ -5,12 +5,14 @@ from starlette.exceptions import HTTPException as StarletteHTTPException from starlette.exceptions import WebSocketException as StarletteWebSocketException from typing_extensions import Annotated, Doc + class EndpointContext(TypedDict, total=False): function: str path: str file: str line: int + class HTTPException(StarletteHTTPException): """ An HTTP exception you can raise in your own code to show errors to the client. diff --git a/fastapi/routing.py b/fastapi/routing.py index 546845701..b8598d7a8 100644 --- a/fastapi/routing.py +++ b/fastapi/routing.py @@ -243,6 +243,7 @@ def _extract_endpoint_context(func: Any) -> EndpointContext: _endpoint_context_cache[func_id] = ctx return ctx + async def serialize_response( *, field: Optional[ModelField] = None, @@ -354,7 +355,11 @@ def get_request_handler( ) # Extract endpoint context for error messages - endpoint_ctx = _extract_endpoint_context(dependant.call) if dependant.call else EndpointContext() + endpoint_ctx = ( + _extract_endpoint_context(dependant.call) + if dependant.call + else EndpointContext() + ) if dependant.path: endpoint_ctx["path"] = f"{request.method} {dependant.path}" @@ -480,7 +485,11 @@ def get_websocket_app( embed_body_fields: bool = False, ) -> Callable[[WebSocket], Coroutine[Any, Any, Any]]: async def app(websocket: WebSocket) -> None: - endpoint_ctx = _extract_endpoint_context(dependant.call) if dependant.call else EndpointContext() + endpoint_ctx = ( + _extract_endpoint_context(dependant.call) + if dependant.call + else EndpointContext() + ) if dependant.path: endpoint_ctx["path"] = f"WS {dependant.path}"