classification
Title: truncate() changes current stream position
Type: behavior Stage: resolved
Components: IO Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: andreymal, nitishch, pitrou
Priority: normal Keywords: patch

Created on 2017-12-05 23:19 by andreymal, last changed 2018-01-28 17:44 by pitrou. This issue is now closed.

Files
File name Uploaded Description Edit
wtf1.py andreymal, 2017-12-05 23:19
Pull Requests
URL Status Linked Edit
PR 4858 merged nitishch, 2017-12-14 05:46
PR 5389 merged pitrou, 2018-01-28 16:42
Messages (4)
msg307698 - (view) Author: andreymal (andreymal) Date: 2017-12-05 23:19
See attached file.

As documentation about "truncate" says, "The current stream position isn’t changed." This is true for most cases. But this is not true for "wtf1.py" example. If you run it with Linux (Tested Debian 8 and Arch; Windows was not tested by me) and Python 3.3+ (or with Python 2.7 using backported "io" module), then these lines:

print('tell:', fp.tell())
print('truncate:', fp.truncate())
print('tell again:', fp.tell())

prints this:

tell: 4098
truncate: 4098
tell again: 4

As you can see, "tell" before truncate and "tell" after truncate are different. Looks like bug.

This bug will not reproduce with Python 2.7 and builtin "open" function; it affects only "io.open".
msg310962 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2018-01-28 16:00
New changeset 059f58ce938d9c3f0286412a4efb1b9131339421 by Antoine Pitrou (Nitish Chandra) in branch 'master':
bpo-32228: Reset raw_pos after unwinding the raw stream (#4858)
https://github.com/python/cpython/commit/059f58ce938d9c3f0286412a4efb1b9131339421
msg310973 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2018-01-28 17:42
New changeset 1d896ed2cddada4455f40782e4120249defbfa70 by Antoine Pitrou in branch '3.6':
[3.6] bpo-32228: Reset raw_pos after unwinding the raw stream (GH-4858) (#5389)
https://github.com/python/cpython/commit/1d896ed2cddada4455f40782e4120249defbfa70
msg310974 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2018-01-28 17:44
I've now pushed Nitish's fix to 3.7 and 3.6.   I have no interest in backporting to 2.7 at this point. Closing!
History
Date User Action Args
2018-01-28 17:44:00pitrousetstatus: open -> closed
versions: + Python 3.7, - Python 2.7, Python 3.4, Python 3.5
messages: + msg310974

resolution: fixed
stage: patch review -> resolved
2018-01-28 17:42:33pitrousetmessages: + msg310973
2018-01-28 16:42:58pitrousetpull_requests: + pull_request5224
2018-01-28 16:00:11pitrousetnosy: + pitrou
messages: + msg310962
2017-12-14 05:46:18nitishchsetkeywords: + patch
stage: patch review
pull_requests: + pull_request4747
2017-12-11 09:37:10nitishchsetnosy: + nitishch
2017-12-05 23:30:42andreymalsettype: behavior
2017-12-05 23:21:27andreymalsettitle: truncate() changes tell() result -> truncate() changes current stream position
2017-12-05 23:19:14andreymalcreate