From 3a49b5b879fdaa893ad5f9662fa25b754d337665 Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Mon, 23 Mar 2026 10:59:39 -0700 Subject: [PATCH] fix: use duck-type in test _get_file_size; fix AsyncGenerator return type annotation --- litellm/llms/custom_httpx/llm_http_handler.py | 3 ++- .../proxy/openai_files_endpoint/test_files_endpoint.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/litellm/llms/custom_httpx/llm_http_handler.py b/litellm/llms/custom_httpx/llm_http_handler.py index b66cad85315..de860ea762c 100644 --- a/litellm/llms/custom_httpx/llm_http_handler.py +++ b/litellm/llms/custom_httpx/llm_http_handler.py @@ -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 diff --git a/tests/test_litellm/proxy/openai_files_endpoint/test_files_endpoint.py b/tests/test_litellm/proxy/openai_files_endpoint/test_files_endpoint.py index ab1fd795d8a..03517c1150b 100644 --- a/tests/test_litellm/proxy/openai_files_endpoint/test_files_endpoint.py +++ b/tests/test_litellm/proxy/openai_files_endpoint/test_files_endpoint.py @@ -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()