From 2b3078fcce6c862e01fc48af0e9b238a368b824a Mon Sep 17 00:00:00 2001 From: 3252a8 <3252a8@proton.me> Date: Sun, 24 May 2026 18:51:37 +0300 Subject: [PATCH] chore: fix formatting checks --- backend/bot/app/web/admin_api_impl/settings.py | 7 ++++--- backend/bot/app/web/admin_api_impl/themes.py | 8 +++----- backend/bot/app/web/admin_settings_manifest.py | 2 +- backend/bot/app/web/webapp/assets.py | 4 +--- backend/bot/app/web/webapp/cache_helpers.py | 8 ++------ backend/bot/app/web/webapp/devices.py | 3 +-- backend/bot/app/web/webapp/guides.py | 4 +--- backend/bot/app/web/webapp/serializers.py | 4 +--- backend/bot/handlers/admin/sync_admin.py | 4 +--- backend/bot/main_bot.py | 3 +++ backend/bot/payment_providers/wata.py | 7 ++----- backend/bot/payment_providers/yookassa.py | 4 +--- backend/bot/services/tariff_worker.py | 3 +-- backend/db/dal/subscription_dal.py | 9 ++++++--- tests/test_admin_webapp_runtime.py | 4 +--- tests/test_main_bot_startup.py | 3 +-- tests/test_security.py | 4 +--- tests/test_subscription_guides_config.py | 10 ++++------ tests/test_subscription_guides_route.py | 4 ++-- tests/test_webapp_themes_config.py | 5 ++++- 20 files changed, 41 insertions(+), 59 deletions(-) diff --git a/backend/bot/app/web/admin_api_impl/settings.py b/backend/bot/app/web/admin_api_impl/settings.py index 2763791..266ea6f 100644 --- a/backend/bot/app/web/admin_api_impl/settings.py +++ b/backend/bot/app/web/admin_api_impl/settings.py @@ -79,9 +79,10 @@ async def admin_settings_patch_route(request: web.Request) -> web.Response: return _error(400, "invalid_updates") if not isinstance(deletes, list): return _error(400, "invalid_deletes") - if "SUBSCRIPTION_PAGE_CONFIG_JSON" in updates and not str( - updates.get("SUBSCRIPTION_PAGE_CONFIG_JSON") or "" - ).strip(): + if ( + "SUBSCRIPTION_PAGE_CONFIG_JSON" in updates + and not str(updates.get("SUBSCRIPTION_PAGE_CONFIG_JSON") or "").strip() + ): updates = dict(updates) updates.pop("SUBSCRIPTION_PAGE_CONFIG_JSON", None) deletes = [*deletes, "SUBSCRIPTION_PAGE_CONFIG_JSON"] diff --git a/backend/bot/app/web/admin_api_impl/themes.py b/backend/bot/app/web/admin_api_impl/themes.py index 129cd9f..21efbe4 100644 --- a/backend/bot/app/web/admin_api_impl/themes.py +++ b/backend/bot/app/web/admin_api_impl/themes.py @@ -66,11 +66,9 @@ def _bump_theme_asset_versions( previous_theme = previous_by_key.get(key) previous_version = int(getattr(previous_theme, "assets_version", 0) or 0) current_version = int(theme.get("assets_version") or 1) - theme_changed = ( - previous_theme is None - or _theme_payload_for_version_compare(theme) - != _theme_payload_for_version_compare(previous_theme) - ) + theme_changed = previous_theme is None or _theme_payload_for_version_compare( + theme + ) != _theme_payload_for_version_compare(previous_theme) if theme_changed or (default_changed and key == config.default_theme): theme["assets_version"] = max(previous_version + 1, current_version, 1) elif previous_version > current_version: diff --git a/backend/bot/app/web/admin_settings_manifest.py b/backend/bot/app/web/admin_settings_manifest.py index 30f68ee..5759479 100644 --- a/backend/bot/app/web/admin_settings_manifest.py +++ b/backend/bot/app/web/admin_settings_manifest.py @@ -211,7 +211,7 @@ SETTINGS_MANIFEST: List[SettingField] = [ "Optional admin JSON override. It is applied only when the JSON override " "switch is enabled." ), - placeholder="{\n \"version\": \"1\"\n}", + placeholder='{\n "version": "1"\n}', ), # ─── Subscription periods & pricing ──────────────────────────── SettingField("MONTH_1_ENABLED", "bool", "pricing", "Тариф 1 месяц"), diff --git a/backend/bot/app/web/webapp/assets.py b/backend/bot/app/web/webapp/assets.py index d5ff26f..be71189 100644 --- a/backend/bot/app/web/webapp/assets.py +++ b/backend/bot/app/web/webapp/assets.py @@ -95,9 +95,7 @@ async def theme_css_asset_route(request: web.Request) -> web.Response: raise web.HTTPNotFound(text="theme_css_not_found") from None query = getattr(request, "query", {}) or {} - cache_control = ( - "public, max-age=31536000, immutable" if query.get("v") else "no-cache" - ) + cache_control = "public, max-age=31536000, immutable" if query.get("v") else "no-cache" try: stat = path.stat() if stat.st_size > WEBAPP_THEME_CSS_MAX_BYTES: diff --git a/backend/bot/app/web/webapp/cache_helpers.py b/backend/bot/app/web/webapp/cache_helpers.py index 7f06157..f42fd4b 100644 --- a/backend/bot/app/web/webapp/cache_helpers.py +++ b/backend/bot/app/web/webapp/cache_helpers.py @@ -66,9 +66,7 @@ def invalidate_local_webapp_user_payload( user_id: int, ) -> None: key = str(int(user_id)) - for (settings_id, cache_namespace, _ttl), cache in tuple( - _WEBAPP_USER_PAYLOAD_CACHES.items() - ): + for (settings_id, cache_namespace, _ttl), cache in tuple(_WEBAPP_USER_PAYLOAD_CACHES.items()): if settings_id == id(settings) and cache_namespace == namespace: cache.invalidate(key) @@ -86,9 +84,7 @@ def invalidate_all_local_webapp_user_payloads( else: namespaces = None - for (settings_id, cache_namespace, _ttl), cache in tuple( - _WEBAPP_USER_PAYLOAD_CACHES.items() - ): + for (settings_id, cache_namespace, _ttl), cache in tuple(_WEBAPP_USER_PAYLOAD_CACHES.items()): if settings_id != id(settings): continue if namespaces is not None and cache_namespace not in namespaces: diff --git a/backend/bot/app/web/webapp/devices.py b/backend/bot/app/web/webapp/devices.py index 6d72641..a90eaa0 100644 --- a/backend/bot/app/web/webapp/devices.py +++ b/backend/bot/app/web/webapp/devices.py @@ -86,8 +86,7 @@ async def _load_devices_payload( "max_devices": max_devices, "max_devices_label": _format_devices_limit(max_devices), "devices": [ - _serialize_device(device, index) - for index, device in enumerate(devices, start=1) + _serialize_device(device, index) for index, device in enumerate(devices, start=1) ], }, } diff --git a/backend/bot/app/web/webapp/guides.py b/backend/bot/app/web/webapp/guides.py index a07f536..c6005c8 100644 --- a/backend/bot/app/web/webapp/guides.py +++ b/backend/bot/app/web/webapp/guides.py @@ -258,9 +258,7 @@ def _public_install_url(request: web.Request, share_token: str) -> str: base = configured_base.rstrip("/") else: host = ( - request.headers.get("X-Forwarded-Host") - or request.headers.get("Host") - or request.host + request.headers.get("X-Forwarded-Host") or request.headers.get("Host") or request.host ) proto = request.headers.get("X-Forwarded-Proto") or request.scheme or "https" base = f"{proto}://{host}" diff --git a/backend/bot/app/web/webapp/serializers.py b/backend/bot/app/web/webapp/serializers.py index 53cc5c8..eeecbbd 100644 --- a/backend/bot/app/web/webapp/serializers.py +++ b/backend/bot/app/web/webapp/serializers.py @@ -340,9 +340,7 @@ def _build_install_share_link( base = configured_base.rstrip("/") else: host = ( - request.headers.get("X-Forwarded-Host") - or request.headers.get("Host") - or request.host + request.headers.get("X-Forwarded-Host") or request.headers.get("Host") or request.host ) proto = request.headers.get("X-Forwarded-Proto") or request.scheme or "https" base = f"{proto}://{host}" diff --git a/backend/bot/handlers/admin/sync_admin.py b/backend/bot/handlers/admin/sync_admin.py index e802b54..49f2d46 100644 --- a/backend/bot/handlers/admin/sync_admin.py +++ b/backend/bot/handlers/admin/sync_admin.py @@ -952,9 +952,7 @@ async def _perform_sync_impl( duplicate_panel_user=panel_user_dict, settings=settings, subscriptions_by_panel_uuid=subscriptions_by_panel_uuid, - active_subscriptions_by_user_panel=( - active_subscriptions_by_user_panel - ), + active_subscriptions_by_user_panel=(active_subscriptions_by_user_panel), ) subscriptions_created += int(merge_result["subscriptions_created"]) subscriptions_updated += int(merge_result["subscriptions_updated"]) diff --git a/backend/bot/main_bot.py b/backend/bot/main_bot.py index 00b7319..7fec8b1 100644 --- a/backend/bot/main_bot.py +++ b/backend/bot/main_bot.py @@ -156,6 +156,7 @@ async def on_startup_configured(dispatcher: Dispatcher): raise SystemExit("WEBHOOK_BASE_URL is required. Polling mode is disabled.") if settings.SUBSCRIPTION_MINI_APP_URL: + async def _configure_mini_app_menu() -> None: menu_text = i18n_instance.gettext( settings.DEFAULT_LANGUAGE, @@ -169,6 +170,7 @@ async def on_startup_configured(dispatcher: Dispatcher): ) await bot.set_chat_menu_button(menu_button=MenuButtonDefault()) logging.info("STARTUP: Mini app domain registered and default menu button restored.") + await _run_telegram_startup_step( "registering mini app menu button", _configure_mini_app_menu, @@ -186,6 +188,7 @@ async def on_startup_configured(dispatcher: Dispatcher): ) await bot.set_my_commands(bot_commands) logging.info("STARTUP: bot command descriptions set.") + await _run_telegram_startup_step( "setting bot commands", _configure_bot_commands, diff --git a/backend/bot/payment_providers/wata.py b/backend/bot/payment_providers/wata.py index 78889b7..1b27cb0 100644 --- a/backend/bot/payment_providers/wata.py +++ b/backend/bot/payment_providers/wata.py @@ -288,9 +288,7 @@ class WataService(HttpClientMixin): return web.Response(status=400, text="bad_request") transaction_id = str(payload.get("transactionId") or "").strip() - payment_link_id = str( - payload.get("paymentLinkId") or payload.get("id") or "" - ).strip() + payment_link_id = str(payload.get("paymentLinkId") or payload.get("id") or "").strip() status = str(payload.get("transactionStatus") or "").strip().lower() order_id_raw = payload.get("orderId") amount_raw = payload.get("amount") @@ -339,8 +337,7 @@ class WataService(HttpClientMixin): except Exception: await session.rollback() logging.exception( - "Wata webhook: failed to persist transaction id %s " - "for payment %s.", + "Wata webhook: failed to persist transaction id %s for payment %s.", transaction_id, payment.payment_id, ) diff --git a/backend/bot/payment_providers/yookassa.py b/backend/bot/payment_providers/yookassa.py index bdb0814..33b0414 100644 --- a/backend/bot/payment_providers/yookassa.py +++ b/backend/bot/payment_providers/yookassa.py @@ -452,9 +452,7 @@ def _resolve_yookassa_activation_amounts( else: months_for_activation = int(traffic_amount_gb) - traffic_gb_for_activation = ( - traffic_amount_gb if is_traffic_sale_base(sale_mode_base) else None - ) + traffic_gb_for_activation = traffic_amount_gb if is_traffic_sale_base(sale_mode_base) else None return ( subscription_months, traffic_amount_gb, diff --git a/backend/bot/services/tariff_worker.py b/backend/bot/services/tariff_worker.py index a6d2ed9..002dc07 100644 --- a/backend/bot/services/tariff_worker.py +++ b/backend/bot/services/tariff_worker.py @@ -321,8 +321,7 @@ class TariffTrafficWorker: sub.skip_notifications = True sub.status_from_panel = "PANEL_USER_NOT_FOUND" logging.warning( - "TariffTrafficWorker: deactivated subscription %s because panel user %s " - "is missing", + "TariffTrafficWorker: deactivated subscription %s because panel user %s is missing", sub.subscription_id, current_uuid, ) diff --git a/backend/db/dal/subscription_dal.py b/backend/db/dal/subscription_dal.py index f02ee33..f8392c3 100644 --- a/backend/db/dal/subscription_dal.py +++ b/backend/db/dal/subscription_dal.py @@ -98,9 +98,12 @@ async def ensure_install_share_token( await session.flush() if result.rowcount: await session.refresh(subscription) - return normalize_install_share_token( - getattr(subscription, "install_share_token", None) - ) or token + return ( + normalize_install_share_token( + getattr(subscription, "install_share_token", None) + ) + or token + ) await session.refresh(subscription) raw_existing = str(getattr(subscription, "install_share_token", "") or "").strip() diff --git a/tests/test_admin_webapp_runtime.py b/tests/test_admin_webapp_runtime.py index d4b6a64..6bbada1 100644 --- a/tests/test_admin_webapp_runtime.py +++ b/tests/test_admin_webapp_runtime.py @@ -53,9 +53,7 @@ class AdminWebappRuntimeTests(unittest.IsolatedAsyncioTestCase): "invalidate_all_webapp_user_payloads", AsyncMock(), ), - patch( - "bot.app.web.admin_api_impl.themes.prune_unused_appearance_assets" - ) as prune_mock, + patch("bot.app.web.admin_api_impl.themes.prune_unused_appearance_assets") as prune_mock, ): await webapp_runtime.refresh_webapp_runtime_after_settings_change( request, diff --git a/tests/test_main_bot_startup.py b/tests/test_main_bot_startup.py index e50aef0..c14cc5a 100644 --- a/tests/test_main_bot_startup.py +++ b/tests/test_main_bot_startup.py @@ -35,8 +35,7 @@ def test_telegram_startup_network_error_retries_until_success_without_traceback( assert calls == ["try", "try", "try"] assert "Telegram network error while registering mini app menu button" in caplog.text assert ( - "Telegram step succeeded while registering mini app menu button on attempt 3" - in caplog.text + "Telegram step succeeded while registering mini app menu button on attempt 3" in caplog.text ) assert "api.telegram.org" in caplog.text assert "Temporary failure in name resolution" in caplog.text diff --git a/tests/test_security.py b/tests/test_security.py index 61cfb6c..fa70525 100644 --- a/tests/test_security.py +++ b/tests/test_security.py @@ -761,9 +761,7 @@ class AdminSettingsSecurityTests(unittest.IsolatedAsyncioTestCase): payload = json.loads(response.text) fields = { - field["key"]: field - for section in payload["sections"] - for field in section["fields"] + field["key"]: field for section in payload["sections"] for field in section["fields"] } self.assertEqual( diff --git a/tests/test_subscription_guides_config.py b/tests/test_subscription_guides_config.py index e26549e..d1eae28 100644 --- a/tests/test_subscription_guides_config.py +++ b/tests/test_subscription_guides_config.py @@ -163,9 +163,7 @@ def test_unsafe_svg_is_rejected(): def test_unsafe_external_link_is_rejected(): config = _config() - config["platforms"]["ios"]["apps"][0]["blocks"][0]["buttons"][0][ - "link" - ] = "javascript:alert(1)" + config["platforms"]["ios"]["apps"][0]["blocks"][0]["buttons"][0]["link"] = "javascript:alert(1)" with pytest.raises(SubscriptionGuidesConfigError, match="unsafe URL scheme"): validate_subscription_guides_config(config) @@ -173,9 +171,9 @@ def test_unsafe_external_link_is_rejected(): def test_external_custom_scheme_is_allowed_for_multiapp_compatibility(): config = _config() - config["platforms"]["ios"]["apps"][0]["blocks"][0]["buttons"][0][ - "link" - ] = "streisand://import/demo" + config["platforms"]["ios"]["apps"][0]["blocks"][0]["buttons"][0]["link"] = ( + "streisand://import/demo" + ) validated = validate_subscription_guides_config(config) diff --git a/tests/test_subscription_guides_route.py b/tests/test_subscription_guides_route.py index 8c00085..def0a4a 100644 --- a/tests/test_subscription_guides_route.py +++ b/tests/test_subscription_guides_route.py @@ -68,7 +68,7 @@ class SubscriptionGuidesRouteTests(unittest.IsolatedAsyncioTestCase): "uuid": default_uuid, "config": json.loads(default_subscription_guides_config_text()), } - ) + ), ) request = self._request(self._settings(), panel_service) @@ -113,7 +113,7 @@ class SubscriptionGuidesRouteTests(unittest.IsolatedAsyncioTestCase): "uuid": default_uuid, "config": json.loads(default_subscription_guides_config_text()), } - ) + ), ) request = self._request( self._settings(SUBSCRIPTION_PAGE_CONFIG_JSON=json.dumps(admin_config)), diff --git a/tests/test_webapp_themes_config.py b/tests/test_webapp_themes_config.py index df33e84..3241896 100644 --- a/tests/test_webapp_themes_config.py +++ b/tests/test_webapp_themes_config.py @@ -396,7 +396,10 @@ class WebappThemesConfigTests(unittest.TestCase): self.assertIn("New webapp surfaces: support, purchase info, password login", css) self.assertIn("Install guide theme surfaces", css) self.assertIn( - ".theme-key-windows95 .support-list-card {\n grid-template-rows: auto auto minmax(0, 1fr);", + ( + ".theme-key-windows95 .support-list-card {\n" + " grid-template-rows: auto auto minmax(0, 1fr);" + ), css, ) self.assertIn(".theme-key-windows95 .traffic-top strong", css)