Repository navigation
Preserve buffered bytes in StreamingIterator - #404
lexingtonhibiki wants to merge 3 commits into
Conversation
Drain the unread buffer before joining the remaining iterator on read(). This prevents data loss after a sized read stops inside a yielded chunk. Cover partial chunks, exhausted iterators, empty input, repeated EOF reads, and equivalent file-like inputs.
Keep finite empty byte chunks from looking like EOF to sized-read consumers. Preserve the buffered read-all correction and file-like behavior, and add regression coverage in the existing streaming iterator test module.
|
Added a related boundary fix in Seven added regressions in the existing test module produced two failures before this change and now pass. An independent AI review also ran a 484-case finite-input comparison: 200 false-EOF/data-loss cases before, zero after. These were local guarded checks, not a full-suite pass. The initial evidence harness executed the seven new test methods only. A subsequent check using an existing pytest environment ran the complete, byte-identical StreamingIterator test module with its fixtures, parameterization, and strict deprecation-warning policy: 33 passed on this head, versus 2 failed / 31 passed on the previous source. Both runs had zero network/process guard events. This isolated module run omits unrelated Betamax cassette configuration; it is not a full-project pytest/tox pass. The new head currently has a failed Read the Docs status: its log stops during checkout with |
Keep text iterator chunks consistent across sized and read-all reads.\nOnly encode text values so existing bytes-like chunks and invalid-input\nTypeError behavior are preserved.
Problem
A sized read can leave unread bytes in
StreamingIterator's internal buffer. A subsequentread()orread(-1)originally joined only the remaining iterator, silently dropping those buffered bytes.Two related read-path inconsistencies are also covered:
TypeError. For example, a UTF-8 text iterator works with repeatedread(1)but failed withread()or a sized read followed byread().Change
TypeErrorbehavior.The file-like input path is unchanged. Regression coverage includes partial chunks, buffered tails after iterator exhaustion, empty input and chunks, stable EOF, UTF-8 and Latin-1 text, mixed text/bytes, bytes-like inputs, and encoding errors.
Current-head validation
Local Python 3.12 focused checks, with DNS/connect and subprocess guards:
DeprecationWarningtreated as an error; zero guard events. The byte-identical test module was run outside the unrelated project cassette configuration.13d1f553: 7 failed / 49 passed. The 23 added cases expose six text read-all inconsistencies plus the encoding-error path, and include compatibility controls.git diff --checkpasses.The initial text-encoding candidate was rejected in review because it also transformed bytes-like and invalid inputs; the final change encodes text types only and preserves those controls.
Older Python versions, the latest full project suite, tox and documentation build have not been run for this head. Hosted CI results are not claimed here; see the checks for the exact current commit.
Historical validation, not current-head full-suite results
The earlier buffered-tail-only revision had 26 StreamingIterator tests passing and 58 focused streaming/multipart/monitor tests passing with three URL-wrapper cases deselected. Its full suite with deprecation warnings ignored had 184 passed / 5 skipped, versus 182 passed / 2 regression failures / 5 skipped for its baseline. Under strict deprecation warnings, that revision had 157 passed / 27 failed / 5 skipped: the baseline had the same 27 Betamax
datetime.utcnow()deprecation failures plus its two regression failures. These historical runs do not validate the latest code as a full-suite pass.Prepared with AI assistance. No dependency changes are included.