From c6dad0bce651a1bef713162328796b9bc06309a0 Mon Sep 17 00:00:00 2001 From: John Davis Date: Mon, 18 Dec 2023 14:10:39 -0500 Subject: [PATCH] Fix linting, add attribution --- lib/galaxy/webapps/galaxy/api/cbv.py | 26 ++++++++++++++++++++------ test/unit/webapps/api/test_cbv.py | 6 +++++- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/galaxy/webapps/galaxy/api/cbv.py b/lib/galaxy/webapps/galaxy/api/cbv.py index 9b2d832c242..853f25c48ba 100644 --- a/lib/galaxy/webapps/galaxy/api/cbv.py +++ b/lib/galaxy/webapps/galaxy/api/cbv.py @@ -1,12 +1,26 @@ +""" +Original implementation by David Montague (@dmontagu) +https://github.com/dmontagu/fastapi-utils +""" from __future__ import annotations import inspect from collections.abc import Callable -from typing import Any, TypeVar, get_type_hints +from typing import ( + Any, + get_type_hints, + TypeVar, +) -from fastapi import APIRouter, Depends +from fastapi import ( + APIRouter, + Depends, +) from pydantic.typing import is_classvar -from starlette.routing import Route, WebSocketRoute +from starlette.routing import ( + Route, + WebSocketRoute, +) T = TypeVar("T") @@ -84,8 +98,8 @@ def _init_cbv(cls: type[Any]) -> None: setattr(self, dep_name, dep_value) old_init(self, *args, **kwargs) - setattr(cls, "__signature__", new_signature) - setattr(cls, "__init__", new_init) + setattr(cls, "__signature__", new_signature) # noqa: B010 + setattr(cls, "__init__", new_init) # noqa: B010 setattr(cls, CBV_CLASS_KEY, True) @@ -102,4 +116,4 @@ def _update_cbv_route_endpoint_signature(cls: type[Any], route: Route | WebSocke parameter.replace(kind=inspect.Parameter.KEYWORD_ONLY) for parameter in old_parameters[1:] ] new_signature = old_signature.replace(parameters=new_parameters) - setattr(route.endpoint, "__signature__", new_signature) + setattr(route.endpoint, "__signature__", new_signature) # noqa: B010 diff --git a/test/unit/webapps/api/test_cbv.py b/test/unit/webapps/api/test_cbv.py index 3ddd912dd09..c8e704e9181 100644 --- a/test/unit/webapps/api/test_cbv.py +++ b/test/unit/webapps/api/test_cbv.py @@ -1,3 +1,7 @@ +""" +Original implementation by David Montague (@dmontagu) +https://github.com/dmontagu/fastapi-utils +""" from __future__ import annotations from typing import ( @@ -79,7 +83,7 @@ def test_multiple_decorators() -> None: @router.get("/items/?") @router.get("/items/{item_path:path}") @router.get("/database/{item_path:path}") - def root(self, item_path: Optional[str] = None, item_query: Optional[str] = None) -> Any: + def root(self, item_path: Optional[str] = None, item_query: Optional[str] = None) -> Any: # noqa: UP007 if item_path: return {"item_path": item_path} if item_query: