diff --git a/src/anthropic/_files.py b/src/anthropic/_files.py index f2a6f94e..ee69d8d1 100644 --- a/src/anthropic/_files.py +++ b/src/anthropic/_files.py @@ -25,9 +25,7 @@ def is_base64_file_input(obj: object) -> TypeGuard[Base64FileInput]: def is_file_content(obj: object) -> TypeGuard[FileContent]: - return ( - isinstance(obj, bytes) or isinstance(obj, tuple) or isinstance(obj, io.IOBase) or isinstance(obj, os.PathLike) - ) + return isinstance(obj, bytes) or isinstance(obj, io.IOBase) or isinstance(obj, os.PathLike) def assert_is_file_content(obj: object, *, key: str | None = None) -> None: diff --git a/tests/test_files.py b/tests/test_files.py index 4b118fe0..42574958 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -21,6 +21,12 @@ def test_tuple_input() -> None: assert result == IsList(IsTuple("file", IsTuple("README.md", IsBytes()))) +def test_tuple_pathlike_input_with_content_type() -> None: + result = to_httpx_files({"file": ("README.md", readme_path, "text/markdown")}) + print(result) + assert result == IsDict({"file": IsTuple("README.md", IsBytes(), "text/markdown")}) + + @pytest.mark.asyncio async def test_async_pathlib_includes_file_name() -> None: result = await async_to_httpx_files({"file": readme_path}) @@ -42,6 +48,13 @@ async def test_async_tuple_input() -> None: assert result == IsList(IsTuple("file", IsTuple("README.md", IsBytes()))) +@pytest.mark.asyncio +async def test_async_tuple_pathlike_input_with_content_type() -> None: + result = await async_to_httpx_files({"file": ("README.md", readme_path, "text/markdown")}) + print(result) + assert result == IsDict({"file": IsTuple("README.md", IsBytes(), "text/markdown")}) + + def test_string_not_allowed() -> None: with pytest.raises(TypeError, match="Expected file types input to be a FileContent type or to be a tuple"): to_httpx_files(