fix: type the forwarded kwargs so basedpyright can check the httpx call

CI's basedpyright budget moved with the base and surfaced 12 new
reportArgumentType errors, ten of them on one line.

`request_kwargs` was typed `dict[str, object]` to keep an earlier gate happy, but
`object` does not unpack into httpx's typed parameters: `stream()` names ten of
them (content, data, files, params, headers, cookies, auth, follow_redirects,
timeout, extensions) and every one was an error. `dict[str, Any]` is what the
values actually are -- whatever `async_safe_get`'s caller passed through -- and it
lets the call be checked instead of merely tolerated.

The other two are the OUTPUT branch's `enumerate(filtered_messages)`. Making
skip_scan conditional on `image_urls` removed pyright's narrowing there, since
skip_scan used to be the only way that name could still be None. It cannot be None
at runtime -- images exist on the request side only, so a response scan returns
early exactly as before -- but the branch now says so with `or ()` rather than
resting on that indirection.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
samtsai15 2026-08-27 16:26:31 +08:00
parent e84522118c
commit c830ee204c
2 changed files with 8 additions and 4 deletions

View file

@ -443,7 +443,7 @@ async def _async_get_capped(
client: object,
url: str,
max_bytes: int,
request_kwargs: dict[str, object], # mutable-ok: forwarded straight to httpx as **kwargs
request_kwargs: dict[str, Any], # mutable-ok: forwarded straight to httpx as **kwargs
) -> httpx.Response:
"""GET ``url``, aborting the transfer once the body exceeds ``max_bytes``.
@ -483,7 +483,7 @@ async def async_safe_get(client: Any, url: str, max_bytes: int | None = None, **
async def _issue(
target_url: str,
request_kwargs: dict[str, object], # mutable-ok: forwarded straight to httpx as **kwargs
request_kwargs: dict[str, Any], # mutable-ok: forwarded straight to httpx as **kwargs
) -> httpx.Response:
if max_bytes is None:
return await client.get(target_url, **request_kwargs)
@ -496,7 +496,7 @@ async def async_safe_get(client: Any, url: str, max_bytes: int | None = None, **
caller_headers: Final = kwargs.pop("headers", {})
for _ in range(_MAX_REDIRECTS):
validated_url, original_host = validate_url(url)
hop_kwargs: dict[str, object] = { # mutable-ok: a fresh per-hop kwargs dict, consumed by this call
hop_kwargs: dict[str, Any] = { # mutable-ok: a fresh per-hop kwargs dict, consumed by this call
**kwargs,
"headers": {**caller_headers, "Host": original_host}, # mutable-ok: httpx takes headers as a dict
"follow_redirects": False,

View file

@ -3465,7 +3465,11 @@ class BedrockGuardrail(CustomGuardrail, BaseAWSLLM):
),
finish_reason="stop",
)
for _idx, _msg in enumerate(filtered_messages)
# `or ()`: skip_scan is now bypassed when an image is present,
# and images exist on the request side only, so a response scan
# still always has messages here. Spelled out rather than left
# leaning on that indirection.
for _idx, _msg in enumerate(filtered_messages or ())
]
)
bedrock_response = await self.make_bedrock_api_request(