From e84522118c9a58eeb0c3b57c93c7a89429978820 Mon Sep 17 00:00:00 2001 From: samtsai15 <6171228+samtsai15@users.noreply.github.com> Date: Thu, 27 Aug 2026 16:11:44 +0800 Subject: [PATCH] style: satisfy LIT010 on the lines this PR touches The base gained LIT010 (assignment without a Final declaration) while this PR was open, so code that passed the gate at the old base now trips it. Three are genuinely never rebound and take Final: `per_message`, `chunks`, and the awaited fetch result, which is now bound separately so the unpack below has room for its reason. Two are real rebinding and say so. `total` is the running byte count the cap is measured against. `mime_type` is overwritten further down when the caller passes `format`, so it cannot be Final; the reason sits on the unpack line itself, since a reason on the preceding line does not count. Co-Authored-By: Claude Opus 5 (1M context) --- litellm/litellm_core_utils/prompt_templates/factory.py | 3 ++- litellm/litellm_core_utils/url_utils.py | 4 ++-- .../proxy/guardrails/guardrail_hooks/bedrock_guardrails.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/litellm/litellm_core_utils/prompt_templates/factory.py b/litellm/litellm_core_utils/prompt_templates/factory.py index 624d5eaac27..ab60e827943 100644 --- a/litellm/litellm_core_utils/prompt_templates/factory.py +++ b/litellm/litellm_core_utils/prompt_templates/factory.py @@ -3571,7 +3571,8 @@ class BedrockImageProcessor: # against the previous signature, so an additive parameter would # break them; omitting it keeps the call byte-for-byte as it was. capped: Final = {} if max_bytes is None else {"max_bytes": max_bytes} # mutable-ok: kwargs for one call - img_bytes, mime_type = await BedrockImageProcessor.get_image_details_async(image_url, **capped) + fetched: Final = await BedrockImageProcessor.get_image_details_async(image_url, **capped) + img_bytes, mime_type = fetched # rebind-ok: mime_type is overridden below by `format` image_format = mime_type.split("/")[1] else: raise ValueError("Unsupported image type. Expected either image url or base64 encoded string") diff --git a/litellm/litellm_core_utils/url_utils.py b/litellm/litellm_core_utils/url_utils.py index 0b26eaa869e..ec3afe7276e 100644 --- a/litellm/litellm_core_utils/url_utils.py +++ b/litellm/litellm_core_utils/url_utils.py @@ -455,8 +455,8 @@ async def _async_get_capped( Returns a fully-read response so callers keep using ``.content`` as before. """ async with _underlying_httpx_client(client).stream("GET", url, **request_kwargs) as response: - chunks: list[bytes] = [] # mutable-ok: accumulator for the capped body - total = 0 + chunks: Final[list[bytes]] = [] # mutable-ok: accumulator for the capped body + total = 0 # rebind-ok: running byte count for the cap async for chunk in response.aiter_bytes(): total += len(chunk) if total > max_bytes: diff --git a/litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py b/litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py index 36a74f9a949..b49040580f7 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py +++ b/litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py @@ -417,7 +417,7 @@ class BedrockGuardrail(CustomGuardrail, BaseAWSLLM): return bedrock_request budget: Final = _ImageFetchBudget() - per_message = await asyncio.gather( + per_message: Final = await asyncio.gather( *(self._build_input_content_items(message=message, budget=budget) for message in messages) ) # mutable-ok: BedrockRequest["content"] is a list in the AWS wire format