chore: verify formatting checks

This commit is contained in:
3252a8
2026-05-27 14:29:45 +03:00
parent 4706be53ab
commit fe34edfe73
19 changed files with 44 additions and 98 deletions
@@ -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,
+1 -3
View File
@@ -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_CONFIG_SCRIPT -->"
WEBAPP_I18N_PLACEHOLDER = "<!-- WEBAPP_I18N_SCRIPT -->"
+4 -12
View File
@@ -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,
)
)
+7 -11
View File
@@ -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),
}
)
+5 -9
View File
@@ -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
@@ -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(
+1 -4
View File
@@ -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)
+2 -6
View File
@@ -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")
+1 -3
View File
@@ -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")
@@ -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)
@@ -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,
@@ -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(
@@ -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)
+1 -2
View File
@@ -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:
+1 -3
View File
@@ -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)
+2 -6
View File
@@ -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",