Skip to content

fix: support PathLike values in file tuples#1410

Open
MukundaKatta wants to merge 1 commit intoanthropics:mainfrom
MukundaKatta:codex/anthropic-pathlike-upload-fix
Open

fix: support PathLike values in file tuples#1410
MukundaKatta wants to merge 1 commit intoanthropics:mainfrom
MukundaKatta:codex/anthropic-pathlike-upload-fix

Conversation

@MukundaKatta
Copy link
Copy Markdown

Summary:

  • stop treating tuples as raw FileContent in _files.py so tuple uploads reach the tuple transformation path
  • support PathLike values inside multipart file tuples as documented by the type hints
  • add sync and async regression tests for tuple PathLike inputs with an explicit content type

Testing:

  • PYTHONPATH=src python3 - <<'PY'
    from pathlib import Path
    from anthropic._files import to_httpx_files
    readme = Path('README.md').resolve()
    result = to_httpx_files({'file': ('README.md', readme, 'text/markdown')})
    assert result['file'][0] == 'README.md'
    assert result['file'][1] == readme.read_bytes()
    assert result['file'][2] == 'text/markdown'
    print('sync ok')
    PY
  • PYTHONPATH=src python3 - <<'PY'
    import asyncio
    from pathlib import Path
    from anthropic._files import async_to_httpx_files
    readme = Path('README.md').resolve()
    async def main():
    result = await async_to_httpx_files({'file': ('README.md', readme, 'text/markdown')})
    assert result['file'][0] == 'README.md'
    assert result['file'][1] == readme.read_bytes()
    assert result['file'][2] == 'text/markdown'
    print('async ok')
    asyncio.run(main())
    PY

Fixes #1318

@MukundaKatta MukundaKatta requested a review from a team as a code owner April 18, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] client.beta.files.upload PathLike error

1 participant