gh-141314: Fix TextIOWrapper.tell() assertion failure with standalone carriage return by mohsinm-dev · Pull Request #141331 · python/cpython
added 2 commits
November 10, 2025 06:31…dalone carriage return When TextIOWrapper.tell() is called after reading a line that ends with a standalone carriage return (\r), the tell optimization algorithm incorrectly assumes there is buffered data to search through. This causes an assertion failure when skip_back=1 exceeds the empty buffer size. The fix detects when next_input is empty and skips the optimization phase, falling back to the byte-by-byte decoding method which always works correctly. This properly handles the architectural constraint that buffer optimization cannot function without buffered data.
- Fix assertion to check skip_bytes instead of skip_back - Use simpler test data b'line1\r' instead of b'line1=1\r' - Remove unnecessary multiple CR test case - Clean up workaround code The assertion was checking wrong variable (skip_back vs skip_bytes). skip_back is search step size, skip_bytes is buffer offset needing validation.
This was referenced
Nov 12, 2025mohsinm-dev added a commit to mohsinm-dev/cpython that referenced this pull request
Nov 12, 2025…th standalone carriage return (pythonGH-141331) The assertion was checking wrong variable (skip_back vs skip_bytes). (cherry picked from commit af80fac) Co-authored-by: Mohsin Mehmood <55545648+mohsinm-dev@users.noreply.github.com>
serhiy-storchaka pushed a commit that referenced this pull request
Nov 12, 2025serhiy-storchaka pushed a commit that referenced this pull request
Nov 12, 2025StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request
Dec 6, 2025…dalone carriage return (pythonGH-141331) The assertion was checking wrong variable (skip_back vs skip_bytes).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters