Why isn't truncate defaulting properly to the current position for files?
<p>In an answer to <a href="https://stackoverflow.com/questions/34858088/truncating-a-text-file-does-not-change-the-file">another question</a>, an odd behavior was observed, specific to Python 3. The <a href="https://docs.python.org/3/library/io.html#io.IOBase.truncate" rel="nofollow noreferrer">documentation for the <code>truncate</code> command</a> states (emphasis mine):</p>

<blockquote>
  <p>Resize the stream to the given size in bytes <strong>(or the current position if size is not specified)</strong>. The current stream position isn’t changed. This resizing can extend or reduce the current file size. In case of extension, the contents of the new file area depend on the platform (on most systems, additional bytes are zero-filled). <strong>The new file size is returned.</strong></p>
</blockquote>

<p>However...</p>

<pre><code>&gt;&gt;&gt; open('temp.txt', 'w').write('ABCDE\nFGHIJ\nKLMNO\nPQRST\nUVWXY\nZ\n')
32
&gt;&gt;&gt; f = open('temp.txt', 'r+')
&gt;&gt;&gt; f.readline()
'ABCDE\n'
&gt;&gt;&gt; f.tell()
6                   # As expected, current position is 6 after the readline
&gt;&gt;&gt; f.truncate()
32                  # ?!
</code></pre>

<p>Instead of truncating at the current position (6), it truncated at the end of the file (i.e. not at all). This was verified by checking the file on disk.</p>

<p>This process works as expected (file truncated to 6 bytes) in Python 2, and also in Python 3 using a <code>StringIO</code> instead of a file. Why is it not working as expected with files in Python 3? Is this a bug?</p>

<p>(Edit: it also works properly if an explicit <code>f.seek(6)</code> is given right before the <code>truncate</code>.)</p>