From a3dd9c1f4ff8318db0e35bda761beda88cf6f53a Mon Sep 17 00:00:00 2001 From: Alex Castillo Date: Wed, 28 Oct 2026 20:54:56 -0400 Subject: [PATCH] fix(cohere): type _parse_tool_call_delta without growing basedpyright counts The reassigned Final local and the untyped chunk lookups added basedpyright errors past the base ceiling. Narrow them with casts; per-rule counts for the file are now at or below the merge-base. Co-Authored-By: Claude Sonnet 5.5 --- litellm/llms/cohere/common_utils.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/litellm/llms/cohere/common_utils.py b/litellm/llms/cohere/common_utils.py index e5f741ccd3d..0d633e9d60b 100644 --- a/litellm/llms/cohere/common_utils.py +++ b/litellm/llms/cohere/common_utils.py @@ -1,5 +1,5 @@ import json -from typing import Final, Literal +from typing import Final, Literal, cast from litellm.llms.base_llm.base_utils import BaseLLMModelInfo from litellm.llms.base_llm.chat.transformation import BaseLLMException @@ -236,12 +236,12 @@ class CohereV2ModelResponseIterator: def _parse_tool_call_delta(self, chunk: dict, index: int) -> ChatCompletionToolCallChunk | None: """Parse tool-call-start and tool-call-delta chunks to extract tool calls.""" - tool_call: Final = chunk.get("delta", {}).get("message", {}).get("tool_calls") or {} - if isinstance(tool_call, list): - tool_call = tool_call[0] if tool_call else {} - function: Final = tool_call.get("function") or {} + delta: Final = cast("dict[str, dict[str, object]]", chunk.get("delta") or {}) + raw: Final = delta.get("message", {}).get("tool_calls") or {} + tool_call: Final = cast("dict[str, object]", (raw[0] if raw else {}) if isinstance(raw, list) else raw) + function: Final = cast("dict[str, str]", tool_call.get("function") or {}) return { - "id": tool_call.get("id"), + "id": cast("str", tool_call.get("id")), "type": "function", "function": { "name": function.get("name"),