Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
mohsinm-dev wants to merge3 commits intopython:main
base:main
Choose a base branch
Loading
frommohsinm-dev:fix-textio-tell-assertion-gh-141314

Conversation

@mohsinm-dev
Copy link
Contributor

@mohsinm-devmohsinm-dev commentedNov 10, 2025
edited by bedevere-appbot
Loading

Summary

  • Fix assertion failure inio.TextIOWrapper.tell() when reading files ending with standalone\r
  • Add comprehensive test case to prevent regression
  • Add NEWS entry documenting the fix

Root Cause

The tell() optimization algorithm assumed buffered data would always be available when calculating position, but files ending with standalone\r create empty snapshots, causingassert(skip_back <= PyBytes_GET_SIZE(next_input)) to fail.

Fix

Added check to skip optimization whennext_input is empty, preventing the assertion failure while maintaining correct position calculation.

Test Plan

  • Added test casetest_tell_after_readline_with_cr intest_textio.py
  • Verified fix handles standalone carriage returns correctly
  • Confirmed all existing io tests still pass
  • Built CPython with debug assertions enabled

…dalone carriage returnWhen TextIOWrapper.tell() is called after reading a line that ends with astandalone carriage return (\r), the tell optimization algorithm incorrectlyassumes there is buffered data to search through. This causes an assertionfailure 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 optimizationcannot function without buffered data.
…dalone carriage returnAdd test case and fix assertion failure in TextIOWrapper.tell() when readingfiles that end with a standalone carriage return (\r). The optimizationalgorithm incorrectly assumed buffered data would always be available,causing an assertion failure when next_input is empty.
- Remove trailing whitespace- Add missing newline at end of NEWS file
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

@mohsinm-dev

[8]ページ先頭

©2009-2025 Movatter.jp