Repository navigation
Keep text streams usable after reverse iteration - #466
codewithfourtix wants to merge 1 commit into
Conversation
Signed-off-by: Ali Zulfiqar <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The touched reverse_iter_lines() code still contains an encoding override that forces UTF-8 for text streams, ignoring both the stream’s encoding and the encoding= argument.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR fixes reverse_iter_lines() so reverse iteration on a caller-owned text stream no longer detaches the underlying buffer (which previously could break subsequent reads and even with-block cleanup), and adds a regression test to ensure the stream remains usable.
Changes:
- Update
reverse_iter_lines()to read fromTextIOWrapper.bufferinstead of callingdetach(). - Add a regression test that reverses, seeks, reads, and closes the same text stream.
File summaries
| File | Description |
|---|---|
boltons/jsonutils.py |
Avoids detaching buffers during reverse iteration by using the existing .buffer on text streams. |
tests/test_jsonutils.py |
Adds a regression test ensuring a text stream still supports seek/read and closes cleanly after reverse iteration. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| orig_obj = file_obj | ||
| try: | ||
| file_obj = orig_obj.detach() | ||
| file_obj = orig_obj.buffer |
Fold #463, #466, #476, #478, #460, #459, and #477 with focused regressions and 26.2.0 release notes. Verified 672 local tests and the full GitHub Actions matrix before merge. Co-authored-by: Ali Zulfiqar <[email protected]> Co-authored-by: Guo Jiarui <[email protected]> Co-authored-by: Nikolaus Schuetz <[email protected]> Co-authored-by: Raiyan Zaman <[email protected]>
|
Folded into #481 with credit (Co-authored-by). Thanks! |
Reverse iteration detaches the buffer from a caller-owned text stream. This makes later reads and even exiting its
withblock raiseValueError. Read from the existing buffer without detaching it.Adds a regression that reverses, seeks, reads, and closes the same text stream.