Python: await Task and Future sources in ResponseStream - #8331
Python: await Task and Future sources in ResponseStream#8331Sun Haoyuan (Shy7777) wants to merge 1 commit into
Conversation
|
@microsoft-github-policy-service agree |
Ricky-7-Yan
left a comment
There was a problem hiding this comment.
Reviewed current head aab491a. Using inspect.isawaitable() is the correct contract-level check here: it includes coroutine objects, asyncio.Task, and Future, while the unchanged __aiter__ branch preserves async-iterable precedence for hybrid sources. The parameterized tests exercise all three awaitable forms through both the constructor and from_awaitable(), including iteration and finalization. I found no blocking issue in the scoped diff.
The repository's full Python workflows have not run on this external branch yet, so this approval is based on the current code/tests plus the author's reported focused 312-test and type-checker runs, not a claim that upstream CI is complete.
Motivation & Context
Scheduling stream initialization with
asyncio.create_task()currently breaksResponseStream, even though its input accepts an awaitable. Task and Future sources are treated as iterators instead of being awaited, so callers get anAttributeErrorduring iteration orRuntimeError: Inner stream not availableduring finalization.Description & Review Guide
isawaitable()check when resolving a stream source. Extend the constructor andfrom_awaitable()tests to cover coroutine, Task, and Future inputs.test_types.pypass with it. Package build, package lint, and the repository pre-commit hooks pass, as do all five configured type checkers on the changed test file and strict Pyright on the changed source file. Full-package Pyright is not green in the minimal local environment: optional provider packages are absent. The full provider test suites were not run.Related Issue
Fixes #8330
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.