diff --git a/Lib/_pyio.py b/Lib/_pyio.py --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -344,10 +344,12 @@ return self.seek(0, 1) def truncate(self, pos=None): - """Truncate file to size bytes. - - Size defaults to the current IO position as reported by tell(). Return - the new size. + """Resize stream to at most size bytes. + + Position in the stream is left unchanged. Size defaults to + the current IO position as reported by tell(). If the stream's + size is increased, the contents of the new file area are + undetermined. Returns the new size. """ self._unsupported("truncate") @@ -1641,10 +1643,12 @@ return os.lseek(self._fd, 0, SEEK_CUR) def truncate(self, size=None): - """Truncate the file to at most size bytes. - - Size defaults to the current file position, as returned by tell(). - The current file position is changed to the value of size. + """Resize stream to at most size bytes. + + Position in the stream is left unchanged. Size defaults to + the current IO position as reported by tell(). If the stream's + size is increased, the contents of the new file area are + undetermined. Returns the new size. """ self._checkClosed() self._checkWritable() @@ -1749,7 +1753,13 @@ self._unsupported("write") def truncate(self, pos=None): - """Truncate size to pos, where pos is an int.""" + """Resize stream to at most size bytes. + + Position in the stream is left unchanged. Size defaults to + the current IO position as reported by tell(). If the stream's + size is increased, the contents of the new file area are + undetermined. Returns the new size. + """ self._unsupported("truncate") def readline(self): diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -584,15 +584,17 @@ size as arg: object = None / -Truncate the file to at most size bytes. +Resize stream to at most size bytes. -Size defaults to the current file position, as returned by tell(). -The current file position is unchanged. Returns the new size. +Position in the stream is left unchanged. Size defaults to +the current IO position as reported by tell(). If the stream's +size is increased, the contents of the new file area are +undetermined. Returns the new size. [clinic start generated code]*/ static PyObject * _io_BytesIO_truncate_impl(bytesio *self, PyObject *arg) -/*[clinic end generated code: output=81e6be60e67ddd66 input=11ed1966835462ba]*/ +/*[clinic end generated code: output=81e6be60e67ddd66 input=473d0e02cc30738b]*/ { Py_ssize_t size; diff --git a/Modules/_io/clinic/bytesio.c.h b/Modules/_io/clinic/bytesio.c.h --- a/Modules/_io/clinic/bytesio.c.h +++ b/Modules/_io/clinic/bytesio.c.h @@ -292,10 +292,12 @@ "truncate($self, size=None, /)\n" "--\n" "\n" -"Truncate the file to at most size bytes.\n" +"Resize stream to at most size bytes.\n" "\n" -"Size defaults to the current file position, as returned by tell().\n" -"The current file position is unchanged. Returns the new size."); +"Position in the stream is left unchanged. Size defaults to\n" +"the current IO position as reported by tell(). If the stream\'s\n" +"size is increased, the contents of the new file area are\n" +"undetermined. Returns the new size."); #define _IO_BYTESIO_TRUNCATE_METHODDEF \ {"truncate", (PyCFunction)_io_BytesIO_truncate, METH_VARARGS, _io_BytesIO_truncate__doc__}, @@ -419,4 +421,4 @@ exit: return return_value; } -/*[clinic end generated code: output=60ce2c6272718431 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=7276c906a3089120 input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/fileio.c.h b/Modules/_io/clinic/fileio.c.h --- a/Modules/_io/clinic/fileio.c.h +++ b/Modules/_io/clinic/fileio.c.h @@ -314,10 +314,12 @@ "truncate($self, size=None, /)\n" "--\n" "\n" -"Truncate the file to at most size bytes and return the truncated size.\n" +"Resize stream to at most size bytes.\n" "\n" -"Size defaults to the current file position, as returned by tell().\n" -"The current file position is changed to the value of size."); +"Position in the stream is left unchanged. Size defaults to\n" +"the current IO position as reported by tell(). If the stream\'s\n" +"size is increased, the contents of the new file area are\n" +"undetermined. Returns the new size."); #define _IO_FILEIO_TRUNCATE_METHODDEF \ {"truncate", (PyCFunction)_io_FileIO_truncate, METH_VARARGS, _io_FileIO_truncate__doc__}, @@ -364,4 +366,4 @@ #ifndef _IO_FILEIO_TRUNCATE_METHODDEF #define _IO_FILEIO_TRUNCATE_METHODDEF #endif /* !defined(_IO_FILEIO_TRUNCATE_METHODDEF) */ -/*[clinic end generated code: output=dcbc39b466598492 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=ff25cfd6fc8e3d0f input=a9049054013a1b77]*/ diff --git a/Modules/_io/clinic/stringio.c.h b/Modules/_io/clinic/stringio.c.h --- a/Modules/_io/clinic/stringio.c.h +++ b/Modules/_io/clinic/stringio.c.h @@ -103,11 +103,12 @@ "truncate($self, pos=None, /)\n" "--\n" "\n" -"Truncate size to pos.\n" +"Resize stream to at most size bytes.\n" "\n" -"The pos argument defaults to the current file position, as\n" -"returned by tell(). The current file position is unchanged.\n" -"Returns the new absolute position."); +"Position in the stream is left unchanged. Size defaults to\n" +"the current IO position as reported by tell(). If the stream\'s\n" +"size is increased, the contents of the new file area are\n" +"undetermined. Returns the new size."); #define _IO_STRINGIO_TRUNCATE_METHODDEF \ {"truncate", (PyCFunction)_io_StringIO_truncate, METH_VARARGS, _io_StringIO_truncate__doc__}, @@ -283,4 +284,4 @@ { return _io_StringIO_seekable_impl(self); } -/*[clinic end generated code: output=f061cf3a20cd14ed input=a9049054013a1b77]*/ +/*[clinic end generated code: output=885c11830d8f3411 input=a9049054013a1b77]*/ diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -988,15 +988,17 @@ size as posobj: object = NULL / -Truncate the file to at most size bytes and return the truncated size. +Resize stream to at most size bytes. -Size defaults to the current file position, as returned by tell(). -The current file position is changed to the value of size. +Position in the stream is left unchanged. Size defaults to +the current IO position as reported by tell(). If the stream's +size is increased, the contents of the new file area are +undetermined. Returns the new size. [clinic start generated code]*/ static PyObject * _io_FileIO_truncate_impl(fileio *self, PyObject *posobj) -/*[clinic end generated code: output=e49ca7a916c176fa input=9026af44686b7318]*/ +/*[clinic end generated code: output=e49ca7a916c176fa input=1957520f803e9c07]*/ { Py_off_t pos; int ret; diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c --- a/Modules/_io/iobase.c +++ b/Modules/_io/iobase.c @@ -127,10 +127,12 @@ } PyDoc_STRVAR(iobase_truncate_doc, - "Truncate file to size bytes.\n" + "Resize stream to at most size bytes.\n" "\n" - "File pointer is left unchanged. Size defaults to the current IO\n" - "position as reported by tell(). Returns the new size."); + "Position in the stream is left unchanged. Size defaults to\n" + "the current IO position as reported by tell(). If the stream's\n" + "size is increased, the contents of the new file area are undetermined.\n" + "Returns the new size."); static PyObject * iobase_truncate(PyObject *self, PyObject *args) diff --git a/Modules/_io/stringio.c b/Modules/_io/stringio.c --- a/Modules/_io/stringio.c +++ b/Modules/_io/stringio.c @@ -462,16 +462,17 @@ pos as arg: object = None / -Truncate size to pos. +Resize stream to at most size bytes. -The pos argument defaults to the current file position, as -returned by tell(). The current file position is unchanged. -Returns the new absolute position. +Position in the stream is left unchanged. Size defaults to +the current IO position as reported by tell(). If the stream's +size is increased, the contents of the new file area are +undetermined. Returns the new size. [clinic start generated code]*/ static PyObject * _io_StringIO_truncate_impl(stringio *self, PyObject *arg) -/*[clinic end generated code: output=6072439c2b01d306 input=748619a494ba53ad]*/ +/*[clinic end generated code: output=6072439c2b01d306 input=0874f292f43baecb]*/ { Py_ssize_t size;