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:
Lance Kuo 2026-05-25 22:53:23 -04:00
parent 7fd8c255e9
commit e77f878061
No known key found for this signature in database
GPG key ID: 548D51586D2EDAD8
2 changed files with 7 additions and 4 deletions

View file

@ -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_.:-]+$``.

View file

@ -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():