From e01a05472ef0bc52a95ea3c5267f57d02c651775 Mon Sep 17 00:00:00 2001 From: yucheng Date: Mon, 10 Aug 2026 19:54:15 +0000 Subject: [PATCH] fix: annotate budget alert claim locals and constants as Final Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- litellm/constants.py | 4 ++-- litellm/proxy/db/budget_alert_claim.py | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/litellm/constants.py b/litellm/constants.py index 487384abb68..9031d9e6d79 100644 --- a/litellm/constants.py +++ b/litellm/constants.py @@ -468,8 +468,8 @@ EMAIL_BUDGET_ALERT_TTL: Final = int(os.getenv("EMAIL_BUDGET_ALERT_TTL", 24 * 60 EMAIL_BUDGET_ALERT_MAX_SPEND_ALERT_PERCENTAGE: Final = float( os.getenv("EMAIL_BUDGET_ALERT_MAX_SPEND_ALERT_PERCENTAGE", 0.8) ) # 80% of max budget -MAX_BUDGET_ALERT_TYPE = "max_budget_alert" -MAX_BUDGET_DEFAULT_ALERT_TYPE = "max_budget_alert_default_threshold" +MAX_BUDGET_ALERT_TYPE: Final = "max_budget_alert" +MAX_BUDGET_DEFAULT_ALERT_TYPE: Final = "max_budget_alert_default_threshold" ############### LLM Provider Constants ############### ### ANTHROPIC CONSTANTS ### ANTHROPIC_TOKEN_COUNTING_BETA_VERSION = os.getenv("ANTHROPIC_TOKEN_COUNTING_BETA_VERSION", "token-counting-2024-11-01") diff --git a/litellm/proxy/db/budget_alert_claim.py b/litellm/proxy/db/budget_alert_claim.py index 9f808121669..d74c3c3b946 100644 --- a/litellm/proxy/db/budget_alert_claim.py +++ b/litellm/proxy/db/budget_alert_claim.py @@ -17,6 +17,7 @@ from __future__ import annotations from collections.abc import Mapping from datetime import datetime, timezone +from typing import Final from litellm._logging import verbose_proxy_logger from litellm.proxy.db.exception_handler import PrismaDBExceptionHandler @@ -31,7 +32,7 @@ def get_budget_window(budget_reset_at: datetime | None, max_budget: float | None lifetime of the key. Including ``max_budget`` means raising or lowering the budget moves every threshold and re-arms the alerts, which is what an operator expects. """ - period = budget_reset_at.isoformat() if budget_reset_at is not None else "" + period: Final = budget_reset_at.isoformat() if budget_reset_at is not None else "" return f"{period}|{max_budget}" @@ -70,7 +71,7 @@ async def claim_budget_alert_slot( if prisma_client is None: return True - identity = _claim_identity(token, alert_type, threshold_pct) + identity: Final = _claim_identity(token, alert_type, threshold_pct) try: await prisma_client.db.litellm_budgetalertsent.create( @@ -88,7 +89,7 @@ async def claim_budget_alert_slot( return True try: - rows_updated = await prisma_client.db.litellm_budgetalertsent.update_many( + rows_updated: Final = await prisma_client.db.litellm_budgetalertsent.update_many( where={**identity, "budget_window": {"not": budget_window}}, # mutable-ok: prisma query payload data={ # mutable-ok: prisma query payload "budget_window": budget_window, @@ -125,7 +126,7 @@ async def release_budget_alert_slot( if prisma_client is None: return - identity = _claim_identity(token, alert_type, threshold_pct) + identity: Final = _claim_identity(token, alert_type, threshold_pct) try: await prisma_client.db.litellm_budgetalertsent.delete_many(