From fe34edfe73ce2ec45ad1e7c74ffc3937b573cc60 Mon Sep 17 00:00:00 2001 From: 3252a8 <3252a8@proton.me> Date: Wed, 27 May 2026 14:29:45 +0300 Subject: [PATCH] chore: verify formatting checks --- .../bot/app/web/admin_api_impl/translations.py | 1 + backend/bot/app/web/webapp/_runtime.py | 4 +--- backend/bot/app/web/webapp/billing.py | 16 ++++------------ backend/bot/app/web/webapp/serializers.py | 18 +++++++----------- backend/bot/handlers/admin/sync_admin.py | 14 +++++--------- backend/bot/handlers/user/subscription/core.py | 4 +--- backend/bot/middlewares/i18n.py | 5 +---- backend/bot/payment_providers/yookassa.py | 8 ++------ backend/bot/services/backup_worker.py | 4 +--- backend/bot/services/panel_webhook_service.py | 4 +--- .../subscription_service_impl/lifecycle.py | 12 +++--------- .../subscription_service_impl/tariffs.py | 4 +--- .../subscription_service_impl/traffic.py | 4 +--- backend/bot/services/tariff_worker.py | 3 +-- backend/db/dal/tariff_dal.py | 4 +--- backend/db/migrator.py | 8 ++------ tests/test_hwid_device_worker.py | 4 +--- tests/test_locale_overrides.py | 16 ++++------------ tests/test_migration_doc_accuracy.py | 9 ++++++--- 19 files changed, 44 insertions(+), 98 deletions(-) diff --git a/backend/bot/app/web/admin_api_impl/translations.py b/backend/bot/app/web/admin_api_impl/translations.py index 57fd34f..928efa6 100644 --- a/backend/bot/app/web/admin_api_impl/translations.py +++ b/backend/bot/app/web/admin_api_impl/translations.py @@ -11,6 +11,7 @@ from bot.services.locale_override_service import ( update_locale_overrides, ) + def _locale_languages( i18n: JsonI18n, overrides: Optional[List[Dict[str, Any]]] = None, diff --git a/backend/bot/app/web/webapp/_runtime.py b/backend/bot/app/web/webapp/_runtime.py index 2cf590a..aad3b35 100644 --- a/backend/bot/app/web/webapp/_runtime.py +++ b/backend/bot/app/web/webapp/_runtime.py @@ -76,9 +76,7 @@ WEBAPP_DEFAULT_LOGO_FILE = WEBAPP_DEFAULT_BRAND_DIR / "default-logo.webp" WEBAPP_DEFAULT_LOGO_PATH = "/webapp-default-logo.webp" WEBAPP_DEFAULT_FAVICON_DIGEST = "19b2a242e5b7bc2d" WEBAPP_DEFAULT_FAVICON_DIR = WEBAPP_DEFAULT_BRAND_DIR / "favicons" / WEBAPP_DEFAULT_FAVICON_DIGEST -WEBAPP_DEFAULT_FAVICON_URL = ( - f"{WEBAPP_FAVICON_PATH}/{WEBAPP_DEFAULT_FAVICON_DIGEST}/icon-180.png" -) +WEBAPP_DEFAULT_FAVICON_URL = f"{WEBAPP_FAVICON_PATH}/{WEBAPP_DEFAULT_FAVICON_DIGEST}/icon-180.png" WEBAPP_EMOJI_CACHE_DIR = APP_ROOT / "data" / "webapp-emoji" WEBAPP_CONFIG_PLACEHOLDER = "" WEBAPP_I18N_PLACEHOLDER = "" diff --git a/backend/bot/app/web/webapp/billing.py b/backend/bot/app/web/webapp/billing.py index e5bc212..6c1522a 100644 --- a/backend/bot/app/web/webapp/billing.py +++ b/backend/bot/app/web/webapp/billing.py @@ -636,15 +636,11 @@ async def device_topup_options_route(request: web.Request) -> web.Response: ) tariff = config.require(sub.tariff_key) if tariff.billing_model != "period": - return _json_error( - 400, "device_topup_unavailable", "Device top-up is not available" - ) + return _json_error(400, "device_topup_unavailable", "Device top-up is not available") lang = db_user.language_code or settings.DEFAULT_LANGUAGE active = await subscription_service.get_active_subscription_details(session, user_id) renewal_available = bool(active and active.get("device_topup_renewal_available")) - extra_hwid_valid_until = ( - active.get("extra_hwid_devices_valid_until") if active else None - ) + extra_hwid_valid_until = active.get("extra_hwid_devices_valid_until") if active else None extra_hwid_valid_until_text = ( active.get("extra_hwid_devices_valid_until_text") if active else None ) or _billing_datetime_text(extra_hwid_valid_until) @@ -716,9 +712,7 @@ async def device_topup_options_route(request: web.Request) -> web.Response: "extra_hwid_devices": int(active.get("extra_hwid_devices") or 0) if active else int(sub.extra_hwid_devices or 0), - "extra_hwid_devices_valid_until": _billing_iso_datetime( - extra_hwid_valid_until - ), + "extra_hwid_devices_valid_until": _billing_iso_datetime(extra_hwid_valid_until), "extra_hwid_devices_valid_until_text": extra_hwid_valid_until_text, "renewal_available": renewal_available, "renewal_recommended_count": int(active.get("extra_hwid_devices") or 0) @@ -978,9 +972,7 @@ async def _create_subscription_payment( hwid_pricing_period_months=hwid_quote.get("pricing_period_months") if hwid_quote else None, - hwid_proration_ratio=hwid_quote.get("proration_ratio") - if hwid_quote - else None, + hwid_proration_ratio=hwid_quote.get("proration_ratio") if hwid_quote else None, hwid_full_price=hwid_quote.get("full_price") if hwid_quote else None, ) ) diff --git a/backend/bot/app/web/webapp/serializers.py b/backend/bot/app/web/webapp/serializers.py index d9bd68f..867a127 100644 --- a/backend/bot/app/web/webapp/serializers.py +++ b/backend/bot/app/web/webapp/serializers.py @@ -611,14 +611,12 @@ def _serialize_tariff_change_target( "mode": "recalc_days", "kind": "free", "title": "recalc_days", - "days_after": int(options.get("recalc_days") or 0), - "remaining_days": int(options.get("remaining_days") or 0), - "converted_hwid_value_rub": float( - options.get("converted_hwid_value_rub") or 0 - ), - "converted_hwid_days": int(options.get("converted_hwid_days") or 0), - } - ) + "days_after": int(options.get("recalc_days") or 0), + "remaining_days": int(options.get("remaining_days") or 0), + "converted_hwid_value_rub": float(options.get("converted_hwid_value_rub") or 0), + "converted_hwid_days": int(options.get("converted_hwid_days") or 0), + } + ) paid_diff = float(options.get("paid_diff_rub") or 0) if paid_diff > 0: actions.append( @@ -638,9 +636,7 @@ def _serialize_tariff_change_target( "title": "convert_days_to_gb", "converted_gb": float(options.get("converted_gb") or 0), "remaining_days": int(options.get("remaining_days") or 0), - "converted_hwid_value_rub": float( - options.get("converted_hwid_value_rub") or 0 - ), + "converted_hwid_value_rub": float(options.get("converted_hwid_value_rub") or 0), "converted_hwid_gb": float(options.get("converted_hwid_gb") or 0), } ) diff --git a/backend/bot/handlers/admin/sync_admin.py b/backend/bot/handlers/admin/sync_admin.py index 261b724..f192be1 100644 --- a/backend/bot/handlers/admin/sync_admin.py +++ b/backend/bot/handlers/admin/sync_admin.py @@ -1203,15 +1203,13 @@ async def _perform_sync_impl( merge_panel_patches = int(merge_result.get("panel_patches", 0)) if merge_panel_patches: panel_patch_count += merge_panel_patches - panel_patch_reason_counts[ - "duplicate_panel_merge_extend" - ] += merge_panel_patches + panel_patch_reason_counts["duplicate_panel_merge_extend"] += ( + merge_panel_patches + ) if merge_result["resolved"]: users_updated += 1 users_uuid_updated += 1 - local_update_reason_counts.update( - ["duplicate_panel_identity_resolved"] - ) + local_update_reason_counts.update(["duplicate_panel_identity_resolved"]) panel_uuids_by_telegram_id.get(telegram_id_from_panel, set()).discard( str(panel_uuid) ) @@ -1322,9 +1320,7 @@ async def _perform_sync_impl( current_panel_user=panel_user_for_identity, reasons=panel_reasons, panel_view=( - "list" - if missing_identity_fields_match - else "full_fetch" + "list" if missing_identity_fields_match else "full_fetch" ), ) panel_patch_count += 1 diff --git a/backend/bot/handlers/user/subscription/core.py b/backend/bot/handlers/user/subscription/core.py index a894948..6d2c149 100644 --- a/backend/bot/handlers/user/subscription/core.py +++ b/backend/bot/handlers/user/subscription/core.py @@ -543,9 +543,7 @@ async def hwid_devices_list_callback( renewal=renewal_available, ) text_key = ( - "select_hwid_device_renewal_package" - if renewal_available - else "select_hwid_device_package" + "select_hwid_device_renewal_package" if renewal_available else "select_hwid_device_package" ) await callback.message.edit_text( get_text( diff --git a/backend/bot/middlewares/i18n.py b/backend/bot/middlewares/i18n.py index cbfa84d..fe34100 100644 --- a/backend/bot/middlewares/i18n.py +++ b/backend/bot/middlewares/i18n.py @@ -160,10 +160,7 @@ def locale_language_flag(code: object) -> str: def sort_locale_language_codes(codes: Iterable[object]) -> List[str]: - normalized = { - normalize_locale_language_code(code, prefer_known_base=False) - for code in codes - } + normalized = {normalize_locale_language_code(code, prefer_known_base=False) for code in codes} normalized = {code for code in normalized if code and is_valid_locale_language_code(code)} preferred = [code for code in DEFAULT_LANGUAGE_ORDER if code in normalized] rest = sorted(code for code in normalized if code not in DEFAULT_LANGUAGE_ORDER) diff --git a/backend/bot/payment_providers/yookassa.py b/backend/bot/payment_providers/yookassa.py index 21c0b78..99793a3 100644 --- a/backend/bot/payment_providers/yookassa.py +++ b/backend/bot/payment_providers/yookassa.py @@ -169,9 +169,7 @@ class YooKassaService: @property def configured(self) -> bool: if not ( - provider_runtime_enabled(self.config) - and self.config.SHOP_ID - and self.config.SECRET_KEY + provider_runtime_enabled(self.config) and self.config.SHOP_ID and self.config.SECRET_KEY ): return False self._ensure_sdk_configured() @@ -1327,9 +1325,7 @@ async def _initiate_yk_payment( "purchased_gb": float(months) if sale_base in {"traffic", "traffic_package", "topup", "premium_topup"} else None, - "purchased_hwid_devices": int(months) - if sale_base in HWID_DEVICE_SALE_BASES - else None, + "purchased_hwid_devices": int(months) if sale_base in HWID_DEVICE_SALE_BASES else None, "hwid_valid_from": hwid_quote.get("valid_from") if hwid_quote else None, "hwid_valid_until": hwid_quote.get("valid_until") if hwid_quote else None, "hwid_pricing_period_months": hwid_quote.get("pricing_period_months") diff --git a/backend/bot/services/backup_worker.py b/backend/bot/services/backup_worker.py index 90dee5d..e48b77e 100644 --- a/backend/bot/services/backup_worker.py +++ b/backend/bot/services/backup_worker.py @@ -213,9 +213,7 @@ class BackupWorker: if not archive_path.exists(): return archive_path for index in range(2, 1000): - candidate = archive_path.with_name( - f"{archive_path.stem}-{index}{archive_path.suffix}" - ) + candidate = archive_path.with_name(f"{archive_path.stem}-{index}{archive_path.suffix}") if not candidate.exists(): return candidate raise RuntimeError("Could not allocate a unique backup archive filename") diff --git a/backend/bot/services/panel_webhook_service.py b/backend/bot/services/panel_webhook_service.py index 94c10e6..1f12b62 100644 --- a/backend/bot/services/panel_webhook_service.py +++ b/backend/bot/services/panel_webhook_service.py @@ -68,9 +68,7 @@ class PanelWebhookService: text = _(message_key, **kwargs) if extra_text: text = f"{text}\n\n{extra_text}" - await self.bot.send_message( - user_id, text, reply_markup=reply_markup - ) + await self.bot.send_message(user_id, text, reply_markup=reply_markup) except Exception: logging.exception("Failed to send notification to %s", user_id) diff --git a/backend/bot/services/subscription_service_impl/lifecycle.py b/backend/bot/services/subscription_service_impl/lifecycle.py index b3b6d5b..f5e05a1 100644 --- a/backend/bot/services/subscription_service_impl/lifecycle.py +++ b/backend/bot/services/subscription_service_impl/lifecycle.py @@ -416,9 +416,7 @@ class SubscriptionLifecycleMixin: "Failed to recalculate active HWID devices for renewal of user %s", user_id, ) - extra_hwid_devices = int( - getattr(current_active_sub, "extra_hwid_devices", 0) or 0 - ) + extra_hwid_devices = int(getattr(current_active_sub, "extra_hwid_devices", 0) or 0) premium_topup_balance_bytes = int( getattr(current_active_sub, "premium_topup_balance_bytes", 0) or 0 ) @@ -813,9 +811,7 @@ class SubscriptionLifecycleMixin: subscription_id=local_active_sub.subscription_id, at=datetime.now(timezone.utc), ) - active_extra_hwid_devices = int( - hwid_entitlement_summary.get("active_devices") or 0 - ) + active_extra_hwid_devices = int(hwid_entitlement_summary.get("active_devices") or 0) if active_extra_hwid_devices != int(local_active_sub.extra_hwid_devices or 0): await subscription_dal.update_subscription( session, @@ -901,9 +897,7 @@ class SubscriptionLifecycleMixin: else None, "extra_hwid_devices": active_extra_hwid_devices, "extra_hwid_devices_valid_until": hwid_entitlement_summary.get("active_until"), - "extra_hwid_devices_next_valid_from": hwid_entitlement_summary.get( - "next_valid_from" - ), + "extra_hwid_devices_next_valid_from": hwid_entitlement_summary.get("next_valid_from"), "user_bot_username": db_user.username, "is_panel_data": True, "max_devices": hwid_limit, diff --git a/backend/bot/services/subscription_service_impl/tariffs.py b/backend/bot/services/subscription_service_impl/tariffs.py index 38a2700..58f4c06 100644 --- a/backend/bot/services/subscription_service_impl/tariffs.py +++ b/backend/bot/services/subscription_service_impl/tariffs.py @@ -441,9 +441,7 @@ class TariffMixin: if options.get("mode") == "period_to_period": target_monthly = float(options.get("target_monthly_rub") or 0) - hwid_days = ( - math.floor((value_rub / target_monthly) * 30) if target_monthly > 0 else 0 - ) + hwid_days = math.floor((value_rub / target_monthly) * 30) if target_monthly > 0 else 0 options["converted_hwid_days"] = max(0, hwid_days) options["recalc_days"] = int(options.get("recalc_days") or 0) + max(0, hwid_days) options["paid_diff_rub"] = max( diff --git a/backend/bot/services/subscription_service_impl/traffic.py b/backend/bot/services/subscription_service_impl/traffic.py index a3b7e49..6da8ae1 100644 --- a/backend/bot/services/subscription_service_impl/traffic.py +++ b/backend/bot/services/subscription_service_impl/traffic.py @@ -54,9 +54,7 @@ class TrafficMixin: purchase_bytes = self.gb_to_bytes(traffic_gb) extra_hwid_devices = ( - await self._active_hwid_extra_devices_for_sub(session, active_sub) - if active_sub - else 0 + await self._active_hwid_extra_devices_for_sub(session, active_sub) if active_sub else 0 ) base_hwid_limit = self._base_hwid_limit_for_tariff(tariff) effective_hwid_limit = self._effective_hwid_limit(base_hwid_limit, extra_hwid_devices) diff --git a/backend/bot/services/tariff_worker.py b/backend/bot/services/tariff_worker.py index a286ec4..0711fd3 100644 --- a/backend/bot/services/tariff_worker.py +++ b/backend/bot/services/tariff_worker.py @@ -795,8 +795,7 @@ class TariffTrafficWorker: if not cached_at: return False return ( - time.monotonic() - float(cached_at) - < TARIFF_WORKER_SQUAD_CONFIRMATION_CACHE_TTL_SECONDS + time.monotonic() - float(cached_at) < TARIFF_WORKER_SQUAD_CONFIRMATION_CACHE_TTL_SECONDS ) def _remember_premium_squad_match(self, cache_key: tuple[str, tuple[str, ...]]) -> None: diff --git a/backend/db/dal/tariff_dal.py b/backend/db/dal/tariff_dal.py index 15b8770..0d2c6de 100644 --- a/backend/db/dal/tariff_dal.py +++ b/backend/db/dal/tariff_dal.py @@ -41,9 +41,7 @@ async def sum_traffic_topups( if created_at_gte is not None: conditions.append(TrafficTopup.created_at >= created_at_gte) result = await session.execute( - select(func.coalesce(func.sum(TrafficTopup.purchased_bytes), 0)).where( - and_(*conditions) - ) + select(func.coalesce(func.sum(TrafficTopup.purchased_bytes), 0)).where(and_(*conditions)) ) return int(result.scalar() or 0) diff --git a/backend/db/migrator.py b/backend/db/migrator.py index 931ac1b..cc32ca1 100644 --- a/backend/db/migrator.py +++ b/backend/db/migrator.py @@ -925,9 +925,7 @@ def _migration_0029_add_hwid_device_purchase_validity(connection: Connection) -> if "hwid_device_purchases" not in table_names or "subscriptions" not in table_names: return - columns: Set[str] = { - col["name"] for col in inspector.get_columns("hwid_device_purchases") - } + columns: Set[str] = {col["name"] for col in inspector.get_columns("hwid_device_purchases")} if "valid_from" not in columns: connection.execute( text("ALTER TABLE hwid_device_purchases ADD COLUMN valid_from TIMESTAMPTZ") @@ -1002,9 +1000,7 @@ def _migration_0030_add_hwid_pricing_metadata(connection: Connection) -> None: connection.execute(text(f"ALTER TABLE payments ADD COLUMN {column} {ddl_type}")) if "tariff_changes" in table_names: - change_columns: Set[str] = { - col["name"] for col in inspector.get_columns("tariff_changes") - } + change_columns: Set[str] = {col["name"] for col in inspector.get_columns("tariff_changes")} change_additions = { "converted_hwid_value_rub": "NUMERIC", "converted_hwid_days": "INTEGER", diff --git a/tests/test_hwid_device_worker.py b/tests/test_hwid_device_worker.py index aea80c4..2fcda43 100644 --- a/tests/test_hwid_device_worker.py +++ b/tests/test_hwid_device_worker.py @@ -42,9 +42,7 @@ class _Service: class HwidDeviceWorkerTests(unittest.IsolatedAsyncioTestCase): async def test_worker_resets_expired_hwid_entitlement_on_panel(self): - panel = SimpleNamespace( - update_user_details_on_panel=AsyncMock(return_value={"ok": True}) - ) + panel = SimpleNamespace(update_user_details_on_panel=AsyncMock(return_value={"ok": True})) worker = TariffTrafficWorker( settings=SimpleNamespace(), session_factory=None, diff --git a/tests/test_locale_overrides.py b/tests/test_locale_overrides.py index 906c3c5..986a669 100644 --- a/tests/test_locale_overrides.py +++ b/tests/test_locale_overrides.py @@ -66,9 +66,7 @@ def _source_files(*roots: str) -> list[Path]: result.append(path) else: result.extend( - child - for child in path.rglob("*") - if child.suffix in {".py", ".js", ".svelte"} + child for child in path.rglob("*") if child.suffix in {".py", ".js", ".svelte"} ) return result @@ -321,9 +319,7 @@ def test_admin_locale_keys_are_split_into_smaller_internal_groups(): "admin_themes_catalog_title": "admin_appearance", "appearance_logo_uploaded_pending": "admin_appearance", "admin_settings_field_yookassa_enabled_label": "admin_settings_payments", - "admin_settings_field_subscription_guides_enabled_label": ( - "admin_settings_subscriptions" - ), + "admin_settings_field_subscription_guides_enabled_label": ("admin_settings_subscriptions"), "admin_settings_field_log_level_label": "admin_settings_notifications", "back_to_admin_panel_button": "admin_navigation", "admin_translations_languages_title": "admin_translations", @@ -534,9 +530,7 @@ def test_load_locale_overrides_uses_db_when_file_missing(tmp_path): assert count == 1 assert i18n.gettext("ru", "welcome") == "Из БД" - assert json.loads(overrides_path.read_text(encoding="utf-8")) == { - "ru": {"welcome": "Из БД"} - } + assert json.loads(overrides_path.read_text(encoding="utf-8")) == {"ru": {"welcome": "Из БД"}} def test_load_locale_overrides_creates_empty_file_when_file_missing_and_db_empty(tmp_path): @@ -706,9 +700,7 @@ def test_update_locale_overrides_accepts_extra_language(tmp_path): assert db_state == {"uk": {"welcome": "Вітаю"}} assert i18n.gettext("uk", "welcome") == "Вітаю" assert i18n.gettext("uk", "plain") == "База" - assert json.loads(overrides_path.read_text(encoding="utf-8")) == { - "uk": {"welcome": "Вітаю"} - } + assert json.loads(overrides_path.read_text(encoding="utf-8")) == {"uk": {"welcome": "Вітаю"}} def test_update_locale_overrides_fails_when_active_file_cannot_be_written(tmp_path): diff --git a/tests/test_migration_doc_accuracy.py b/tests/test_migration_doc_accuracy.py index 5af59d7..30503c7 100644 --- a/tests/test_migration_doc_accuracy.py +++ b/tests/test_migration_doc_accuracy.py @@ -64,14 +64,16 @@ class MigrationDocumentationFactsTests(unittest.TestCase): missing = sorted(name for name in EXPECTED_CONTAINER_NAMES if name not in self.doc) self.assertFalse( missing, - f"migrations/remnawave-tg-shop.md is missing container names from current compose: {missing}", + "migrations/remnawave-tg-shop.md is missing container names " + f"from current compose: {missing}", ) def test_doc_lists_every_volume_in_current_compose(self): missing = sorted(name for name in EXPECTED_VOLUME_NAMES if name not in self.doc) self.assertFalse( missing, - f"migrations/remnawave-tg-shop.md is missing volume names from current compose: {missing}", + "migrations/remnawave-tg-shop.md is missing volume names " + f"from current compose: {missing}", ) def test_doc_warns_about_renamed_telegram_webhook_secret(self): @@ -234,7 +236,8 @@ class DocComposeFileReferencesTests(unittest.TestCase): self.assertIn(relpath, doc) self.assertTrue( (REPO_ROOT / relpath).is_file(), - f"{relpath} is referenced in migrations/remnawave-tg-shop.md but missing on disk", + f"{relpath} is referenced in migrations/remnawave-tg-shop.md " + "but missing on disk", ) def test_doc_references_migrator_module_path(self):