-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-141314: Fix TextIOWrapper.tell() assertion failure with standalone carriage return #141331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
serhiy-storchaka
merged 6 commits into
python:main
from
mohsinm-dev:fix-textio-tell-assertion-gh-141314
Nov 11, 2025
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fe6dd19
gh-141314: Fix TextIOWrapper.tell() assertion failure with standalone…
mohsinm-dev 69960dc
gh-141314: Fix TextIOWrapper.tell() assertion failure with standalone…
mohsinm-dev cdb9283
Fix linting issues
mohsinm-dev b1e1885
Refactor code structure and add test for multiple CR cases
mohsinm-dev 1d9f77f
Fix trailing whitespace in test file
mohsinm-dev e84d686
Fix TextIOWrapper assertion typo and simplify test
mohsinm-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
gh-141314: Fix TextIOWrapper.tell() assertion failure with standalone…
… 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.
- Loading branch information
commit fe6dd199f46dc23e29cb9e4d6e1261d2656cf13d
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -686,6 +686,24 @@ def test_multibyte_seek_and_tell(self): | |
| self.assertEqual(f.tell(), p1) | ||
| f.close() | ||
|
|
||
| def test_tell_after_readline_with_cr(self): | ||
| # Test for gh-141314: TextIOWrapper.tell() assertion failure | ||
| # when dealing with standalone carriage returns | ||
| data = b'line1=1\r' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can be simply |
||
| with self.open(os_helper.TESTFN, "wb") as f: | ||
| f.write(data) | ||
|
|
||
| with self.open(os_helper.TESTFN, "r") as f: | ||
| # Read line that ends with \r | ||
| line = f.readline() | ||
| self.assertEqual(line, "line1=1\n") | ||
| # This should not cause an assertion failure | ||
| pos = f.tell() | ||
| # Verify we can seek back to this position | ||
| f.seek(pos) | ||
| remaining = f.read() | ||
| self.assertEqual(remaining, "") | ||
|
|
||
| def test_seek_with_encoder_state(self): | ||
| f = self.open(os_helper.TESTFN, "w", encoding="euc_jis_2004") | ||
| f.write("\u00e6\u0300") | ||
|
|
||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.