You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TextIOWrapper.tell() returns a wrong position after next() and flush() #161055
TextIOWrapper.__next__() stops updating the decoder snapshot that tell() relies on and disables tell() (OSError: telling position disabled by next() call), but flush() re-enables tell() without restoring the snapshot. tell() then computes the position from a stale snapshot and silently returns a wrong cookie.
This prints 3624 and 'bbb' instead of 10003 and 'c\n' (or the OSError that tell() raises without the flush() call); _pyio.TextIOWrapper returns 9768, also wrong. If the snapshot was replaced by an earlier seek(), tell() instead raises OSError: can't reconstruct logical file position (before gh-161053 it read past the snapshot).
gh-81217 asks for next() not to disable tell() at all.
The repro still prints 3624 and 'bbb' on current main (9768 with _pyio). Calling next() as the first read, then flush() and tell(), is another way to trigger the bug.
The PR makes flush() re-enable tell() only when no internal snapshot state or decoded text is pending, so in these cases tell() raises the same OSError as without the flush() call; seek() and reaching the end of iteration still re-enable it.
Activity
gpshead commentedon Nov 1, 2026
The repro still prints
3624and'bbb'on current main (9768with_pyio). Callingnext()as the first read, thenflush()andtell(), is another way to trigger the bug.The PR makes
flush()re-enabletell()only when no internal snapshot state or decoded text is pending, so in these casestell()raises the sameOSErroras without theflush()call;seek()and reaching the end of iteration still re-enable it.