refactor(api): move file processing polling into SDK-owned helpers (#3712)
- [x] I understand that this repository is auto-generated and my pull request may not be merged ## Changes being requested Move the existing sync and async file-processing polling bodies into SDK-owned `lib/_files.py`. `Files.wait_for_processing` and `AsyncFiles.wait_for_processing` keep their public signatures, defaults, docstrings, and return types, and delegate to the helpers. No schema, compiler, dependency, or generation-metadata changes are needed. The polling bodies are unchanged apart from renaming the receiver from `self` to `files`. This preserves the `processed`/`error`/`deleted` terminal states, wall-clock timing, dynamic `retrieve` and `_sleep` hooks, return identity, and exact errors. In particular, the strict `>` timeout check still happens after a repeated retrieval, even if that retrieval returns a terminal state. This does not introduce a generic polling framework or change existing timeout behavior. Review pointers: - Original public methods: [sync](https://github.com/openai/openai-python/blob/bedb9a7b8839e193107e88b92f7cc166f08ac83d/src/openai/resources/files.py#L366) and [async](https://github.com/openai/openai-python/blob/bedb9a7b8839e193107e88b92f7cc166f08ac83d/src/openai/resources/files.py#L720). - [Extracted bodies](https://github.com/openai/openai-python/blob/3dfdf85e4d33a3274270aadccda6278c41ac8ede/src/openai/lib/_files.py#L12). - [Focused regression tests](https://github.com/openai/openai-python/blob/3dfdf85e4d33a3274270aadccda6278c41ac8ede/tests/lib/test_file_processing.py#L36): 13 cases covering sync/async terminal results, polling, timeout and retrieval-error propagation, plus async cancellation. Following the [review discussion](https://github.com/openai/openai-python/pull/3712#discussion_r3830698221), the new handwritten suite is limited to 87 lines rather than an exhaustive matrix of clock, timeout, and event-order details. Existing Files API tests are unchanged. The review revision changes only this new test file; runtime source remains byte-identical to the original PR head. ## Additional context & links Validation: - Commands: `TEST_API_BASE_URL=http://127.0.0.1:4141 .venv/bin/python -m pytest tests/lib/test_file_processing.py tests/api_resources/test_files.py -q -n 0` and the same command using `.venv-pydantic-v1/bin/python`: **130 passed, 3 skipped** in each Pydantic mode. The skips are the existing aiohttp/respx2-incompatible `test_method_content`, `test_raw_response_content`, and `test_streaming_response_content` cases. - Commands: `.venv/bin/ruff format tests/lib/test_file_processing.py` and `./scripts/lint` passed on the review revision, including Ruff, Pyright, mypy, and import checks. The initial full `./scripts/format` also passed; unrelated reporter-formatting changes were excluded. - Command: `./scripts/build` passed. Both the wheel and source distribution contain `openai/lib/_files.py`; importing the helper and resource classes from the built wheel also passed. - Exact source/AST comparison against the base verified both polling bodies, all other resource statements, public signatures, exports, request construction, and response wrappers. The verified custom-code report keeps 36 mixed files and changes only the Files resource customization, shrinking it from **+47/-0 to +26/-0**. The other 35 customizations are unchanged. Reproduction command: ```sh python3 scripts/castiron/custom_code_report.py report \ --base bedb9a7b8839e193107e88b92f7cc166f08ac83d \ --head 3dfdf85e4d33a3274270aadccda6278c41ac8ede \ --fetch --require-head-hash --public \ --out /tmp/castiron-file-processing ```
A
Alex Chang committed
5f20c51c694801cb0a4d0fed413bedc1bac2dda0
Parent: a002ef3
Committed by GitHub <noreply@github.com>
on 8/21/2026, 3:36:10 PM