From 5365c3fdcc21506fb6141e0b0cfe1ac1bc0f69bd Mon Sep 17 00:00:00 2001 From: MHammett Date: Sun, 16 Aug 2026 20:23:34 -0500 Subject: [PATCH] style(responses): satisfy the LIT010 type-discipline gate The four locals in _convert_response_format_to_text_param were assigned without Final, which the gate counts as open to rebinding -- LIT010 sits at its ceiling, so four new ones tripped it. None of them is ever rebound, so Final is simply correct here and matches the rest of the file. Building `text_format_param` by mutation was also the only reason it needed to stay non-Final. Replaced with a comprehension merged into the returned literal, which reads better and drops one LIT011 in-place mutation as well. No behaviour change: the tests are untouched and still pass, and 5 of the 8 still fail without the fix commit. --- litellm/responses/utils.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/litellm/responses/utils.py b/litellm/responses/utils.py index 5f7cea89cb5..733f4f17f31 100644 --- a/litellm/responses/utils.py +++ b/litellm/responses/utils.py @@ -939,24 +939,25 @@ class ResponsesAPIRequestUtils: from litellm.llms.base_llm.base_utils import type_to_response_format_param # Normalizes a Pydantic model into a response_format dict; passes a dict through. - converted = type_to_response_format_param(response_format) + converted: Final = type_to_response_format_param(response_format) if converted is None: return None - format_type = converted.get("type") + format_type: Final = converted.get("type") if format_type is None: return None if format_type != "json_schema": return {"format": {"type": format_type}} - json_schema = converted.get("json_schema") or {} - text_format_param: dict = {"type": format_type} + json_schema: Final = converted.get("json_schema") or {} # `name`/`schema` are required by the API and `strict`/`description` are optional, # so copy whatever was supplied and let the provider reject a malformed schema. - for key in ("name", "schema", "strict", "description"): - if json_schema.get(key) is not None: - text_format_param[key] = json_schema[key] - return {"format": text_format_param} + schema_fields: Final = { + key: json_schema[key] + for key in ("name", "schema", "strict", "description") + if json_schema.get(key) is not None + } + return {"format": {"type": format_type, **schema_fields}} @staticmethod def convert_text_format_to_text_param(