From 20a84fdf5fc16f51dcdf027ad37118a4ccff2f33 Mon Sep 17 00:00:00 2001 From: Alexey Kotenko Date: Tue, 30 Jan 2024 12:19:47 +0000 Subject: [PATCH] Reformat --- fastapi/applications.py | 26 ++++++++++++++------------ fastapi/routing.py | 8 ++++---- tests/test_operations_signatures.py | 8 ++++++-- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/fastapi/applications.py b/fastapi/applications.py index a5405eff4..871ac3da6 100644 --- a/fastapi/applications.py +++ b/fastapi/applications.py @@ -1028,6 +1028,7 @@ class FastAPI(Starlette): self.add_route(self.docs_url, swagger_ui_html, include_in_schema=False) if self.swagger_ui_oauth2_redirect_url: + async def swagger_ui_redirect(req: Request) -> HTMLResponse: return get_swagger_ui_oauth2_redirect_html() @@ -1037,6 +1038,7 @@ class FastAPI(Starlette): include_in_schema=False, ) if self.openapi_url and self.redoc_url: + async def redoc_html(req: Request) -> HTMLResponse: root_path = req.scope.get("root_path", "").rstrip("/") openapi_url = root_path + self.openapi_url @@ -1828,7 +1830,7 @@ class FastAPI(Starlette): callbacks=callbacks, openapi_extra=openapi_extra, generate_unique_id_function=generate_unique_id_function, - **kwargs + **kwargs, ) def put( @@ -2162,7 +2164,7 @@ class FastAPI(Starlette): """ ), ] = Default(generate_unique_id), - **kwargs: Any + **kwargs: Any, ) -> Callable[[DecoratedCallable], DecoratedCallable]: """ Add a *path operation* using an HTTP PUT operation. @@ -2209,7 +2211,7 @@ class FastAPI(Starlette): callbacks=callbacks, openapi_extra=openapi_extra, generate_unique_id_function=generate_unique_id_function, - **kwargs + **kwargs, ) def post( @@ -2543,7 +2545,7 @@ class FastAPI(Starlette): """ ), ] = Default(generate_unique_id), - **kwargs: Any + **kwargs: Any, ) -> Callable[[DecoratedCallable], DecoratedCallable]: """ Add a *path operation* using an HTTP POST operation. @@ -2924,7 +2926,7 @@ class FastAPI(Starlette): """ ), ] = Default(generate_unique_id), - **kwargs: Any + **kwargs: Any, ) -> Callable[[DecoratedCallable], DecoratedCallable]: """ Add a *path operation* using an HTTP DELETE operation. @@ -3300,7 +3302,7 @@ class FastAPI(Starlette): """ ), ] = Default(generate_unique_id), - **kwargs: Any + **kwargs: Any, ) -> Callable[[DecoratedCallable], DecoratedCallable]: """ Add a *path operation* using an HTTP OPTIONS operation. @@ -3342,7 +3344,7 @@ class FastAPI(Starlette): callbacks=callbacks, openapi_extra=openapi_extra, generate_unique_id_function=generate_unique_id_function, - **kwargs + **kwargs, ) def head( @@ -3676,7 +3678,7 @@ class FastAPI(Starlette): """ ), ] = Default(generate_unique_id), - **kwargs: Any + **kwargs: Any, ) -> Callable[[DecoratedCallable], DecoratedCallable]: """ Add a *path operation* using an HTTP HEAD operation. @@ -3718,7 +3720,7 @@ class FastAPI(Starlette): callbacks=callbacks, openapi_extra=openapi_extra, generate_unique_id_function=generate_unique_id_function, - **kwargs + **kwargs, ) def patch( @@ -4052,7 +4054,7 @@ class FastAPI(Starlette): """ ), ] = Default(generate_unique_id), - **kwargs: Any + **kwargs: Any, ) -> Callable[[DecoratedCallable], DecoratedCallable]: """ Add a *path operation* using an HTTP PATCH operation. @@ -4099,7 +4101,7 @@ class FastAPI(Starlette): openapi_extra=openapi_extra, generate_unique_id_function=generate_unique_id_function, # *args, - **kwargs + **kwargs, ) def trace( @@ -4475,7 +4477,7 @@ class FastAPI(Starlette): callbacks=callbacks, openapi_extra=openapi_extra, generate_unique_id_function=generate_unique_id_function, - **kwargs + **kwargs, ) def websocket_route( diff --git a/fastapi/routing.py b/fastapi/routing.py index f922dec8c..2324be65d 100644 --- a/fastapi/routing.py +++ b/fastapi/routing.py @@ -796,7 +796,7 @@ class APIRouter(routing.Router): """ ), ] = Default(generate_unique_id), - **kwargs: Any + **kwargs: Any, ) -> None: super().__init__( routes=routes, @@ -923,7 +923,7 @@ class APIRouter(routing.Router): callbacks=current_callbacks, openapi_extra=openapi_extra, generate_unique_id_function=current_generate_unique_id, - **kwargs + **kwargs, ) self.routes.append(route) @@ -1300,7 +1300,7 @@ class APIRouter(routing.Router): callbacks=current_callbacks, openapi_extra=route.openapi_extra, generate_unique_id_function=current_generate_unique_id, - **kwargs + **kwargs, ) elif isinstance(route, routing.Route): methods = list(route.methods or []) @@ -2428,7 +2428,7 @@ class APIRouter(routing.Router): """ ), ] = Default(generate_unique_id), - **kwargs: Any + **kwargs: Any, ) -> Callable[[DecoratedCallable], DecoratedCallable]: """ Add a *path operation* using an HTTP POST operation. diff --git a/tests/test_operations_signatures.py b/tests/test_operations_signatures.py index 7859fa234..832f9a0c9 100644 --- a/tests/test_operations_signatures.py +++ b/tests/test_operations_signatures.py @@ -4,8 +4,12 @@ import pytest from fastapi import APIRouter, FastAPI -@pytest.mark.parametrize('method_name', ["get", "put", "post", "delete", "options", "head", "patch", "trace"]) -@pytest.mark.parametrize('sig_param', inspect.signature(APIRouter.get).parameters.items()) +@pytest.mark.parametrize( + "method_name", ["get", "put", "post", "delete", "options", "head", "patch", "trace"] +) +@pytest.mark.parametrize( + "sig_param", inspect.signature(APIRouter.get).parameters.items() +) def test_signatures_consistency(method_name, sig_param): router_method = getattr(APIRouter, method_name) app_method = getattr(FastAPI, method_name)