From 9087a2a1a63283262973e9b806db3afd1aad7614 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 21 Sep 2025 16:18: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/routing.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/fastapi/routing.py b/fastapi/routing.py index 0777a8619..dd1ddd0a9 100644 --- a/fastapi/routing.py +++ b/fastapi/routing.py @@ -83,6 +83,7 @@ if sys.version_info >= (3, 13): # pragma: no cover else: # pragma: no cover from asyncio import iscoroutinefunction + # Copy of starlette.routing.request_response modified to include the # dependencies' AsyncExitStack def request_response( @@ -117,11 +118,13 @@ def request_response( "and is not raising the exception again. Read more about it in the " "docs: https://fastapi.tiangolo.com/tutorial/dependencies/dependencies-with-yield/#dependencies-with-yield-and-except" ) + # Same as in Starlette await wrap_app_handling_exceptions(app, request)(scope, receive, send) return app + # Copy of starlette.routing.websocket_session modified to include the # dependencies' AsyncExitStack def websocket_session( @@ -141,6 +144,7 @@ def websocket_session( scope["fastapi_inner_astack"] = stack # Same as in Starlette await func(session) + # Same as in Starlette await wrap_app_handling_exceptions(app, session)(scope, receive, send) @@ -312,9 +316,9 @@ def get_request_handler( async def app(request: Request) -> Response: response: Union[Response, None] = None file_stack = request.scope.get("fastapi_middleware_astack") - assert isinstance( - file_stack, AsyncExitStack - ), "fastapi_astack not found in request scope" + assert isinstance(file_stack, AsyncExitStack), ( + "fastapi_astack not found in request scope" + ) # Read body and auto-close files try: @@ -367,9 +371,9 @@ def get_request_handler( # Solve dependencies and run path operation function, auto-closing dependencies errors: List[Any] = [] async_exit_stack = request.scope.get("fastapi_inner_astack") - assert isinstance( - async_exit_stack, AsyncExitStack - ), "fastapi_inner_astack not found in request scope" + assert isinstance(async_exit_stack, AsyncExitStack), ( + "fastapi_inner_astack not found in request scope" + ) solved_result = await solve_dependencies( request=request, dependant=dependant, @@ -437,9 +441,9 @@ def get_websocket_app( ) -> Callable[[WebSocket], Coroutine[Any, Any, Any]]: async def app(websocket: WebSocket) -> None: async_exit_stack = websocket.scope.get("fastapi_inner_astack") - assert isinstance( - async_exit_stack, AsyncExitStack - ), "fastapi_inner_astack not found in request scope" + assert isinstance(async_exit_stack, AsyncExitStack), ( + "fastapi_inner_astack not found in request scope" + ) solved_result = await solve_dependencies( request=websocket, dependant=dependant,