From ba0f7a01ef93ea7915edeb6be5a307dee92c1a65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Wed, 2 Jul 2025 13:02:47 +0200 Subject: [PATCH] chore: reduce max complexity lint (#3230) --- lnbits/app.py | 2 +- lnbits/commands.py | 2 +- lnbits/core/crud/payments.py | 2 +- lnbits/core/views/api.py | 2 +- lnbits/db.py | 2 +- lnbits/exceptions.py | 2 +- lnbits/wallets/nwc.py | 2 +- lnbits/wallets/strike.py | 2 +- pyproject.toml | 3 +-- tests/wallets/test_nwc_wallets.py | 2 +- 10 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lnbits/app.py b/lnbits/app.py index 2c2e3459..ce65960e 100644 --- a/lnbits/app.py +++ b/lnbits/app.py @@ -277,7 +277,7 @@ async def check_installed_extensions(app: FastAPI): logger.info(f"{ext.id} ({ext.installed_version})") -async def build_all_installed_extensions_list( +async def build_all_installed_extensions_list( # noqa: C901 include_deactivated: Optional[bool] = True, ) -> list[InstallableExtension]: """ diff --git a/lnbits/commands.py b/lnbits/commands.py index 7b3ec71c..3c03c5c5 100644 --- a/lnbits/commands.py +++ b/lnbits/commands.py @@ -353,7 +353,7 @@ async def extensions_list(): help="Admin user ID (must have permissions to install extensions).", ) @coro -async def extensions_update( +async def extensions_update( # noqa: C901 extension: Optional[str] = None, all_extensions: Optional[bool] = False, repo_index: Optional[str] = None, diff --git a/lnbits/core/crud/payments.py b/lnbits/core/crud/payments.py index 000bff02..c63b10cf 100644 --- a/lnbits/core/crud/payments.py +++ b/lnbits/core/crud/payments.py @@ -92,7 +92,7 @@ async def get_latest_payments_by_extension( ) -async def get_payments_paginated( +async def get_payments_paginated( # noqa: C901 *, wallet_id: Optional[str] = None, user_id: Optional[str] = None, diff --git a/lnbits/core/views/api.py b/lnbits/core/views/api.py index 20583d77..313a3173 100644 --- a/lnbits/core/views/api.py +++ b/lnbits/core/views/api.py @@ -93,7 +93,7 @@ async def api_create_account(data: CreateWallet) -> Wallet: @api_router.get("/api/v1/lnurlscan/{code}") -async def api_lnurlscan( +async def api_lnurlscan( # noqa: C901 code: str, wallet: WalletTypeInfo = Depends(require_invoice_key) ): try: diff --git a/lnbits/db.py b/lnbits/db.py index f362f30e..85cd4277 100644 --- a/lnbits/db.py +++ b/lnbits/db.py @@ -658,7 +658,7 @@ def dict_to_submodel(model: type[TModel], value: dict | str) -> TModel | None: return dict_to_model(_subdict, model) -def dict_to_model(_row: dict, model: type[TModel]) -> TModel: +def dict_to_model(_row: dict, model: type[TModel]) -> TModel: # noqa: C901 """ Convert a dictionary with JSON-encoded nested models to a Pydantic model :param _dict: Dictionary from database diff --git a/lnbits/exceptions.py b/lnbits/exceptions.py index 3eab2759..28bebf04 100644 --- a/lnbits/exceptions.py +++ b/lnbits/exceptions.py @@ -69,7 +69,7 @@ def render_html_error(request: Request, exc: Exception) -> Optional[Response]: ) -def register_exception_handlers(app: FastAPI): +def register_exception_handlers(app: FastAPI): # noqa: C901 """Register exception handlers for the FastAPI app""" @app.exception_handler(Exception) diff --git a/lnbits/wallets/nwc.py b/lnbits/wallets/nwc.py index c0b02a7c..e6b3b9f8 100644 --- a/lnbits/wallets/nwc.py +++ b/lnbits/wallets/nwc.py @@ -513,7 +513,7 @@ class NWCConnection: if subscription: # Check if the subscription exists first subscription["future"].set_exception(Exception(info)) - async def _on_event_message(self, msg: list[Union[str, dict]]): + async def _on_event_message(self, msg: list[Union[str, dict]]): # noqa: C901 """ Handles EVENT messages from the relay. """ diff --git a/lnbits/wallets/strike.py b/lnbits/wallets/strike.py index 3040a0eb..7f9ff8b1 100644 --- a/lnbits/wallets/strike.py +++ b/lnbits/wallets/strike.py @@ -487,7 +487,7 @@ class StrikeWallet(Wallet): return None - async def _get_payment_status_by_checking_id( + async def _get_payment_status_by_checking_id( # noqa: C901 self, checking_id: str ) -> PaymentStatus: r_payment = await self._get(f"/payments/{checking_id}") diff --git a/pyproject.toml b/pyproject.toml index cab993a2..1b54074e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -211,8 +211,7 @@ classmethod-decorators = [ ] [tool.ruff.lint.mccabe] -# TODO: Decrease this to 10. -max-complexity = 16 +max-complexity = 10 [tool.ruff.lint.flake8-bugbear] # Allow default arguments like, e.g., `data: List[str] = fastapi.Query(None)`. diff --git a/tests/wallets/test_nwc_wallets.py b/tests/wallets/test_nwc_wallets.py index 491c62df..ec59e7e8 100644 --- a/tests/wallets/test_nwc_wallets.py +++ b/tests/wallets/test_nwc_wallets.py @@ -74,7 +74,7 @@ def sign_event(pub_key, priv_key, event): return event -async def handle(wallet, mock_settings, data, websocket, path): +async def handle(wallet, mock_settings, data, websocket, path): # noqa: C901 async for message in websocket: if not wallet: continue