classification
Title: truncate() changes current stream position
Type: behavior Stage: patch review
Components: IO Versions: Python 3.6, Python 3.5, Python 3.4, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: andreymal, nitishch
Priority: normal Keywords: patch

Created on 2017-12-05 23:19 by andreymal, last changed 2017-12-14 05:46 by nitishch.

Files
File name Uploaded Description Edit
wtf1.py andreymal, 2017-12-05 23:19
Pull Requests
URL Status Linked Edit
PR 4858 open nitishch, 2017-12-14 05:46
Messages (1)
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".
History
Date User Action Args
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