fix: read PathLike content inside upload tuples - #3614
Conversation
ting-hong-shieh
left a comment
There was a problem hiding this comment.
I'm requesting changes because the production patch is identical to #3474 and carries forward the boundary problem already identified in that review.
is_file_content() is declared as TypeGuard[FileContent], but it returns True for tuples even though _types.py defines FileContent as IO[bytes] | bytes | PathLike and models upload tuples separately in FileTypes. Moving the tuple branch ahead of that predicate makes the reported PathLike case pass, but it leaves the type guard unsound and makes correctness depend on branch order.
Please make is_file_content() match the FileContent alias, then update assert_is_file_content() to accept and validate the supported tuple forms explicitly (or add a separate, correctly typed FileTypes predicate). Since #3474 already tracks this implementation for #3473, consolidating the correction there would keep the issue on one implementation path.
Validated at exact head bc52b78f11a8f71866f1126bf562c981e272e0d7 against base/current main d9029e3ada3c008b4631d78a425743445730892a:
tests/test_files.pyandtests/test_extract_files.py: 26 passed.- Ruff lint and format checks passed on both changed files.
- Pyright passed with 0 errors.
git diff --checkpassed.src/openai/_files.pyis identical to the current #3474 head, where the same predicate correction remains requested.
No API call, credential, or external service was used.
Summary
Fixes #3473.
Verification
uv run --with pytest --with pytest-asyncio --with dirty-equals python -m pytest tests/test_files.py tests/test_extract_files.py -q -o addopts=uv run --with ruff ruff check src/openai/_files.py tests/test_files.pyuv run --with ruff ruff format --check src/openai/_files.py tests/test_files.pyuv run --with pyright --with pytest --with pytest-asyncio --with dirty-equals scripts/run-pyright src/openai/_files.py tests/test_files.pyuv run python -c "import openai; print(openai.__version__)"