mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-03 02:22:24 +00:00
fix(types): revert make_valid_bedrock_tool_use_id to str -> str
CI mypy failed on the Optional[str] annotation greptile suggested in #28825: factory.py:4033 - Incompatible types (expression has type 'str | None', TypedDict item 'toolUseId' has type 'str') (and two more at the same call sites) Downstream BedrockToolUseBlock and BedrockToolResultBlock require str. The sibling make_valid_bedrock_tool_name has the same None-passthrough and the same str -> str annotation for the same reason; keeping symmetry. Restored the # type: ignore[arg-type] on the empty-passthrough test with a comment explaining the signature trade-off.
This commit is contained in:
parent
7fd8c255e9
commit
e77f878061
2 changed files with 7 additions and 4 deletions
|
|
@ -5361,9 +5361,7 @@ def make_valid_bedrock_tool_name(input_tool_name: str) -> str:
|
|||
return valid_string
|
||||
|
||||
|
||||
def make_valid_bedrock_tool_use_id(
|
||||
input_tool_use_id: Optional[str],
|
||||
) -> Optional[str]:
|
||||
def make_valid_bedrock_tool_use_id(input_tool_use_id: str) -> str:
|
||||
"""
|
||||
Replaces any invalid characters in the input tool_use_id with underscores
|
||||
so it matches Bedrock Converse's required pattern ``^[a-zA-Z0-9_.:-]+$``.
|
||||
|
|
|
|||
|
|
@ -2818,7 +2818,12 @@ def test_make_valid_bedrock_tool_use_id_empty_passthrough():
|
|||
)
|
||||
|
||||
assert make_valid_bedrock_tool_use_id("") == ""
|
||||
assert make_valid_bedrock_tool_use_id(None) is None
|
||||
# The signature is ``str -> str`` to match downstream TypedDict callers
|
||||
# (``BedrockToolUseBlock.toolUseId``); the helper still defensively returns
|
||||
# the input unchanged when None slips in. Suppress the resulting mypy
|
||||
# error here — annotating the helper as ``Optional[str]`` would force a
|
||||
# cascade of ``cast(str, ...)`` calls at the use sites.
|
||||
assert make_valid_bedrock_tool_use_id(None) is None # type: ignore[arg-type]
|
||||
|
||||
|
||||
def test_bedrock_tool_call_invoke_sanitizes_drifted_name_and_id():
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue