fix: add missing __aiter__ to TextGenerationStream for async for loops#196
Conversation
Without __aiter__, async for chunk in stream: raises TypeError: 'TextGenerationStream' object is not an async iterable. This makes async streaming completely broken when _is_async=True.
|
Hey @adambalogh this is something critical you need to take action quickly guys ! |
|
Thanks for your contribution! |
|
There's still some pr opened can you check them on your X dm or let me provide them here too Hey team,Just pushed 4 bug fix PRs to the OpenGradient-SDK repo — all critical issues found during a code audit. Here's a quick summary:🔴 PR #196 — Async Streaming Completely Broken 🔴 PR #197 — TEE Metadata Lost in Streaming Responses 🟠 PR #198 — run_with_retry Silently Returns None 🟡 PR #199 — Public Types Missing from all |
Bug
TextGenerationStreamimplements__anext__for async iteration but is missing the required__aiter__protocol method.Any code using
async for chunk in stream:when_is_async=Truewill crash with:This silently breaks all async streaming usage — a critical runtime regression.
Root Cause
Python's async iteration protocol requires both
__aiter__(to return the iterator) and__anext__(to yield items). Only__anext__was implemented.From the Python data model docs:
Fix
Added
__aiter__method that validates the_is_asyncflag and returnsself:Impact
async for chunk in stream:pattern documented in SDK examples and READMETesting