Skip to content

Preserve unread text when SpooledStringIO rolls over - #582

Open
Aryangupta-05 wants to merge 1 commit into
mahmoud:masterfrom
Aryangupta-05:fix/spooled-text-rollover-position
Open

Aryangupta-05 wants to merge 1 commit into
mahmoud:masterfrom
Aryangupta-05:fix/spooled-text-rollover-position

Conversation

@Aryangupta-05

Copy link
Copy Markdown

The change

Fixes #581. Preserve the UTF-8 reader's pending bytes, decoded characters and buffered lines when SpooledStringIO rolls over to a temporary file. Keeping only the underlying byte position skips unread text after readline() and can raise UnicodeDecodeError if 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 --check passed. 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

  • Harness/tooling: OpenAI Codex. Investigation, code, tests and this description (including the backstory draft) were AI-assisted. No claim of personal production use or independent human review is made.
  • Model: GPT-6 through Codex; the exact model variant is not exposed in this session.
  • Original prompts: The account owner asked for five useful open-source contributions across different established repositories for learning and career opportunities. The latest continuation prompt was now conitnue to do your work. When asked for a personal backstory, the owner requested genrate 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.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SpooledStringIO.rollover() skips unread text after readline()

1 participant