Terry J. Reedy <tjre...@udel.edu> added the comment:

This should not have been closed yet.

The announced policy is that bugfix releases should not add or change APIs. I 
think this hidden change (there is no What' New in 3.1.2 doc) should be 
reverted in 3.1.3. I will post on py-dev for other opinions.

That aside, I think both the current behavior and docs are buggy and should be 
changed for 3.2 (and 3.1.3 if not reverted).

1. If the file pointer is not moved, then it seems to me that line 3 of my 
example output should have been '\0\0\0\0' instead of ''. The current behavior 
is '' + 'abc\n' == '\0\0\0\0abc\n', which is not sane. Maybe .getvalue() needs 
to be changed. It is hard to further critique the observed behavior since the 
intent is, to me, essentially undocumented.

2. The current 3.1.2/3.2a0 manual entry

"truncate(size=None)
    Truncate the file to at most size bytes. size defaults to the current file 
position, as returned by tell(). Note that the current file position isn’t 
changed; if you want to change it to the new end of file, you have to seek() 
explicitly."

 has several problems.

a. 'file' should be changed to 'stream' to be consistent with other entries.

b. If "truncate the file to at most size bytes" does not mean 'change the steam 
position', then I have no idea what it is supposed to mean, or what .truncate 
is actually supposed to do.

c. There is no mention that what is does do is to replace existing chars with 
null chars. (And the effect of that is/should be different in Python than in C.)

d. There is no mention of the return value and what *it* is supposed to mean.

3. The current 3.1.2 (and I presume, 3.2a0) doc string (help entry)

"truncate(...)
    Truncate size to pos.
    
    The pos argument defaults to the current file position, as
    returned by tell().  The current file position is unchanged.
    Returns the new absolute position."

also has problems.

a. Same change of 'file' to 'stream'.

b. I already commented on ... and 'truncate size to pos', but to be consistent 
with the manual, the arg should be called 'size' rather that 'pos', or vice 
verse.

c. 'truncate' does not define the meaning of 'truncate', especially when it no 
longer means what a native English speaker would expect it to mean.

d. To me, 'the *new* absolute position' contradicts 'The current file position 
is *unchanged*' [emphases added]. Is there some subtle, undocumented, 
distinction between 'absolute position' and 'file [stream] position'?

In any case, .truncate(0) returns 0, which seems to become the new position for 
.getvalue() but not for appending chars with print. To me, having *two* steams 
positions for different functions is definitely a bug.

4. There is no mention of a change to .truncate in What's New in Python 3.2.

After searching more, I see that the change was discussed in #6939, by only two 
people. I see no justification there for changing 3.1 instead of waiting for 
3.2. The OP suggested in his initial message, as I do here, that the doc say 
something about what .truncate does do with respect to padding, but that did 
not happen.

----------
resolution: rejected -> 
status: closed -> open

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue8840>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to