Repository navigation
Preserve unread text when SpooledStringIO rolls over - #582
Aryangupta-05 wants to merge 1 commit into
Conversation
Retain pending UTF-8 bytes, decoded characters and buffered lines so rollover and fileno do not skip unread text or start decoding mid-character. Fixes mahmoud#581. AI assistance: OpenAI Codex (GPT-6) investigated, implemented and validated this change at the account owner request.
|
I ran additional checks on base 4e5faa3 and head f3017b5 using CPython 3.12.15 on Linux. All 166 reading cases matched a text model and io.StringIO on head, including fragment boundaries and positions. Base differed in 64 cases. These are additional manifestations of the known read ahead problem, not 64 new defects. The set includes Unicode, CRLF and repeated rollover and fileno calls. In 36 mixed operation, length query and error cases, head matched its behavior without rollover. This checks compatibility rather than independent correctness of those operations. Each set was repeated three times with matching case records, and two targeted mutations were detected. No head regression was observed in this finite set. The full suite and other platforms were not tested. I have attached a short report and reproducible evidence. This was AI assisted using Codex and GPT 6.1 Sol, after reading the patch and existing tests. |
The change
Fixes #581. Preserve the UTF-8 reader's pending bytes, decoded characters and buffered lines when
SpooledStringIOrolls over to a temporary file. Keeping only the underlying byte position skips unread text afterreadline()and can raiseUnicodeDecodeErrorif read-ahead ended inside a multibyte character.The patch keeps the existing byte position and transfers the reader buffers, preserving existing read/write behavior. Tests cover explicit rollover,
fileno(), automatic rollover during a write, multiline and multibyte text, and a length-query compatibility boundary. Existing length-query behavior is outside this fix's scope.Validation: full tests and doctests on Windows / CPython 3.11: 681 passed, 18 subtests passed.
git diff --checkpassed. The regression tests fail on the original implementation with skipped text or a Unicode decoding error. The full suite needed normal local socket access for an unrelated Windows asyncio test.The backstory
i'm getting started with open source and want to learn by fixing real bugs. small, reusable python utilities interest me because they're a practical way to understand how reliable library code is built. this report was selected while looking for an existing bug to contribute to; it did not come from prior production use of boltons.
AI assistance
now conitnue to do your work. When asked for a personal backstory, the owner requestedgenrate a sentnce and make it all in lower case letter and human text. The backstory above is a disclosed draft based on that stated intent.