Skip to content

gh-161055: Fix TextIOWrapper.tell() after next() and flush() - #161056

Open
gpshead wants to merge 1 commit into
python:mainfrom
gpshead:textio-flush-tell-161055
Open

gpshead wants to merge 1 commit into
python:mainfrom
gpshead:textio-flush-tell-161055

Conversation

@gpshead

@gpshead gpshead commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

TextIOWrapper.__next__() stops updating the decoder snapshot that tell() uses, but flush() re-enabled tell() unconditionally, so tell() returned a wrong position (and failed an assertion in debug builds when next() was the first read). flush() now re-enables tell() only when there is neither a snapshot nor pending decoded text, which keeps tell() working after a write() or a read() to EOF that follows next(). seek(), which relied on flush() for this, now re-enables it itself, in both the C and Python implementations. The position cannot be recovered without the snapshot, so tell() raises the same OSError it raises without the flush() call; letting next() keep tell() working is gh-81217.

Fixes #161055

flush() re-enabled tell() while the decoder snapshot was stale from
next(), so tell() returned a wrong position.  seek() now re-enables
tell() itself.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextIOWrapper.tell() returns a wrong position after next() and flush()

1 participant