[BUG] `client.beta.files.upload` `PathLike` error
Based on the function signatures, client.beta.files.upload should support a PathLike as the second element in the tuple.
https://github.com/anthropics/anthropic-sdk-python/blob/d7c0974ce6ab94ca135b10b2a45308203c0e0c7e/src/anthropic/resources/beta/files.py#L571-L582 https://github.com/anthropics/anthropic-sdk-python/blob/d7c0974ce6ab94ca135b10b2a45308203c0e0c7e/src/anthropic/_types.py#L69-L78 https://github.com/anthropics/anthropic-sdk-python/blob/d7c0974ce6ab94ca135b10b2a45308203c0e0c7e/src/anthropic/_types.py#L58
But if I pass something like file=("foo.txt", Path("foo.txt"), "text/plain") to upload it fails because in to_httpx_files -> _transform_file the first if block catches the tuple so the second if in the function that handles reading in the PathLike contents for tuples is unreachable.
https://github.com/anthropics/anthropic-sdk-python/blob/d7c0974ce6ab94ca135b10b2a45308203c0e0c7e/src/anthropic/_files.py#L49-L74 https://github.com/anthropics/anthropic-sdk-python/blob/d7c0974ce6ab94ca135b10b2a45308203c0e0c7e/src/anthropic/_files.py#L27-L30
Hi! I'd like to fix this.
I traced the exact bug: is_file_content() returns True for any tuple (it checks isinstance(obj, tuple)), so when you pass ("foo.txt", Path("foo.txt"), "text/plain") the function hits the is_file_content branch first and returns the raw tuple unchanged — the is_tuple_t branch below is unreachable.
Fix: swap the order in both _transform_file and _async_transform_file — check is_tuple_t first, then is_file_content. Tuples will then be routed through read_file_content(file[1]) which already handles PathLike correctly.
Would a PR be welcome? I can add a test covering (name, Path(...), mime) tuples as well.
Will be fixed in the next release (https://github.com/anthropics/anthropic-sdk-python/pull/1810/changes/070f95332daea9dc3ed19fe91251d6e5285e5560)