fix(streaming): type the dict-usage unpack for the basedpyright gate

Usage(**response_obj["usage"]) unpacks a dict whose value type pyright
cannot see, and the delta gate reports that once per typed constructor
parameter: five, against the three .get() calls the line replaced. Moving
the unpack behind _usage_from_payload keeps the same Usage(**payload)
call and is reported once, at the call site, so the rule count ends below
its merge base
This commit is contained in:
Ambuj Upadhyay 2026-10-09 21:47:19 +05:30
parent 55bbea9b87
commit d5fb65f41b

View file

@ -1394,7 +1394,7 @@ class CustomStreamWrapper:
setattr(
model_response,
"usage",
litellm.Usage(**response_obj["usage"]),
_usage_from_payload(response_obj["usage"]),
)
elif isinstance(response_obj["usage"], Usage):
setattr(
@ -2421,6 +2421,11 @@ class CustomStreamWrapper:
_strip_sse_data_from_chunk = strip_sse_data_from_chunk
def _usage_from_payload(payload: Mapping[str, Any]) -> Usage:
"""Build ``Usage`` from a wire-shaped usage dict, forwarding every key."""
return litellm.Usage(**payload)
def _cache_token_count(details: PromptTokensDetailsWrapper | None, keys: tuple[str, ...]) -> int:
for key in keys:
value = getattr(details, key, None)