Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(lint): Partly fix basedpyright lint issues

KnyazSh014d7b87b5ca
diff --git a/litellm/llms/gigachat/chat/streaming.py b/litellm/llms/gigachat/chat/streaming.py
index e7ca0bec83d..7bdca61fd0f 100644
--- a/litellm/llms/gigachat/chat/streaming.py
+++ b/litellm/llms/gigachat/chat/streaming.py
@@ -75,21 +75,21 @@ class GigaChatModelResponseIterator:
if chunk_finish_reason == "stop":
usage_data: Final = chunk.get("usage") or {} # mutable-ok: empty dict default
- if usage_data:
- validated_usage: Final = {
- k: int(v) for k, v in dict(usage_data).items()
- } # rebind-ok: dict comprehension
+ if usage_data and isinstance(usage_data, dict):
+ validated_usage: Final = {k: int(v) for k, v in usage_data.items()}
usage = convert_usage(validated_usage)
- usage_block = ChatCompletionUsageBlock(
+ _prompt_details: dict | None = (
+ usage.prompt_tokens_details.model_dump() if usage.prompt_tokens_details else None
+ ) # rebind-ok: conditional
+ _completion_details: dict | None = (
+ usage.completion_tokens_details.model_dump() if usage.completion_tokens_details else None
+ ) # rebind-ok: conditional
+ usage_block = ChatCompletionUsageBlock( # pyright: ignore[reportCallIssue] # TypedDict kwarg constructor
prompt_tokens=usage.prompt_tokens,
completion_tokens=usage.completion_tokens,
total_tokens=usage.total_tokens,
- prompt_tokens_details=(
- usage.prompt_tokens_details.model_dump() if usage.prompt_tokens_details else None
- ),
- completion_tokens_details=(
- usage.completion_tokens_details.model_dump() if usage.completion_tokens_details else None
- ),
+ prompt_tokens_details=_prompt_details,
+ completion_tokens_details=_completion_details,
)
return GenericStreamingChunk(
diff --git a/litellm/passthrough/main.py b/litellm/passthrough/main.py
index a64aa894221..1715ec10f30 100644
--- a/litellm/passthrough/main.py
+++ b/litellm/passthrough/main.py
@@ -152,7 +152,7 @@ class AsyncPassthroughStreamingResponse(AsyncGenerator[Any, Any]):
) -> bytes:
if not self._initialized:
await self # pyright: ignore[reportGeneralTypeIssues] # structural type check misses __await__
- return await self._iterator.athrow(typ, val, tb)
+ return await self._iterator.athrow(typ, val, tb) # pyright: ignore[reportCallIssue, reportArgumentType] # matches one of the athrow overloads
async def aclose(self) -> None:
self._start_flush()
@@ -226,7 +226,7 @@ class PassthroughStreamingResponse(Generator[Any, Any, Any]):
val: BaseException | object = None,
tb: TracebackType | None = None,
) -> bytes:
- return self._iterator.throw(typ, val, tb)
+ return self._iterator.throw(typ, val, tb) # pyright: ignore[reportCallIssue, reportArgumentType] # matches one of the throw overloads
def close(self) -> None:
self._start_flush()
@@ -488,10 +488,13 @@ def llm_passthrough_route(
forward_headers=False,
)
+ _request_data: dict | None = (
+ data if isinstance(data, dict) else (json if isinstance(json, dict) else None)
+ ) # rebind-ok: conditional
headers, signed_json_body = provider_config.sign_request(
headers=headers,
litellm_params=litellm_params_dict,
- request_data=data if data else json,
+ request_data=_request_data,
api_base=str(updated_url),
model=model,
)
@@ -513,9 +516,12 @@ def llm_passthrough_route(
)
## IS STREAMING REQUEST
+ _streaming_request_data: dict = (
+ data if isinstance(data, dict) else (json if isinstance(json, dict) else {})
+ ) # rebind-ok: conditional
is_streaming_request: Final = provider_config.is_streaming_request(
endpoint=endpoint,
- request_data=data or json or {},
+ request_data=_streaming_request_data,
)
# Update logging object with streaming status