fix(anthropic): annotate thought-signature helpers with Final (LIT010)

Satisfy type_discipline_gate LIT010 on the five assignments this PR
introduced: pad, base_id, signature/function_signature, and parts.
This commit is contained in:
Li-john1021 2026-10-14 18:59:21 +08:00
parent 8d182ccae4
commit f1adc665d2
2 changed files with 7 additions and 7 deletions

View file

@ -1792,7 +1792,7 @@ def encode_thought_signature_for_anthropic_tool_id(signature: str) -> str:
def decode_thought_signature_from_anthropic_tool_id(encoded: str) -> str:
"""Inverse of ``encode_thought_signature_for_anthropic_tool_id``."""
pad = (-len(encoded)) % 4
pad: Final = (-len(encoded)) % 4
return base64.urlsafe_b64decode(encoded + ("=" * pad)).decode("utf-8")
@ -1806,7 +1806,7 @@ def format_anthropic_tool_use_id_with_signature(raw_id: str, thought_signature:
signature after ``__thought__`` lets those clients round-trip the real
signature the same way OpenAI-compatible clients do via ``tool_calls[].id``.
"""
base_id = normalize_anthropic_tool_use_id(raw_id)
base_id: Final = normalize_anthropic_tool_use_id(raw_id)
if not thought_signature:
return base_id
return f"{base_id}{THOUGHT_SIGNATURE_SEPARATOR}{encode_thought_signature_for_anthropic_tool_id(thought_signature)}"

View file

@ -367,19 +367,19 @@ class LiteLLMAnthropicMessagesAdapter:
"""
fields: Final = _optional_attr(tool_call, "provider_specific_fields")
if fields:
signature = _thought_signature(fields)
signature: Final = _thought_signature(fields)
if signature:
return signature
function_fields: Final = _optional_attr(_optional_attr(tool_call, "function"), "provider_specific_fields")
if function_fields:
signature = _thought_signature(function_fields)
if signature:
return signature
function_signature: Final = _thought_signature(function_fields)
if function_signature:
return function_signature
raw_id: Final = _optional_attr(tool_call, "id")
if isinstance(raw_id, str) and THOUGHT_SIGNATURE_SEPARATOR in raw_id:
parts = raw_id.split(THOUGHT_SIGNATURE_SEPARATOR, 1)
parts: Final = raw_id.split(THOUGHT_SIGNATURE_SEPARATOR, 1)
if len(parts) == 2 and parts[1]:
return parts[1]