Repository navigation
Conversation
Previously, `__aiter__` was implemented as a generator function, and as such could get garbage collected when not completely exhausted in a way that has recent versions of `trio` complaining. Using a real, if trivial, object to do this causes less complaints. Fixes encode#3686
Wkhanex
left a comment
There was a problem hiding this comment.
At 357b42fdefa4, I tested independent iterators over the same ByteStream, including an empty payload and a 65,537-byte payload. Both iterators yielded the original bytes; the first remained exhausted on repeated reads, and starting a fresh iterator replayed the original bytes. Dropping a partially consumed iterator and forcing collection produced no async-generator/resource warning under either asyncio or Trio.
All 55 additional assertions passed, along with the existing content module (43 tests). The empty-payload and two-interleaved-iterator cases are useful regression controls for the None sentinel and per-iterator consumed state. AI-assisted CPython 3.12 validation; this is scoped to byte streams and the content tests.
Summary
Previously,
__aiter__was implemented as a generator function, and as such could get garbage collected when not completely exhausted in a way that has (recent versions of)triocomplaining:Using a real, if trivial, object to do this causes less complaints.
Fixes #3686
Closes #3700 (fix for the same issue)
Checklist