fix: use duck-type in test _get_file_size; fix AsyncGenerator return type annotation

This commit is contained in:
Ishaan Jaffer 2026-03-23 10:59:39 -07:00
parent 6a9b84e788
commit 3a49b5b879
2 changed files with 5 additions and 4 deletions

View file

@ -4,6 +4,7 @@ import ssl
from typing import (
TYPE_CHECKING,
Any,
AsyncGenerator,
AsyncIterator,
Coroutine,
Dict,
@ -154,7 +155,7 @@ else:
async def _async_file_chunks(
fp: Any, chunk_size: int = 65536
) -> "AsyncIterator[bytes]":
) -> "AsyncGenerator[bytes, None]":
"""Async generator that reads a sync file-like object in chunks via a thread executor.
Dispatches each blocking disk read to a thread pool via anyio so the async

View file

@ -2,7 +2,7 @@ import io
import json
import os
import sys
from typing import Union
from typing import Any, Union
from unittest.mock import ANY
import pytest
@ -25,9 +25,9 @@ from litellm.types.llms.openai import OpenAIFileObject
client = TestClient(app)
def _get_file_size(file_content: Union[bytes, io.IOBase]) -> int:
def _get_file_size(file_content: Union[bytes, Any]) -> int:
"""Return file size without loading IO objects fully into memory."""
if isinstance(file_content, io.IOBase):
if hasattr(file_content, "read") and hasattr(file_content, "seek"):
pos = file_content.tell()
file_content.seek(0, 2)
size = file_content.tell()