Issue #20699: Document that “io” methods accept bytes-like objects

This matches the usage of ZipFile and BufferedWriter. This still requires
return values to be bytes() objects.

Also document and test that the write() methods should only access their
argument before they return.
This commit is contained in:
Martin Panter 2016-05-28 00:41:57 +00:00
parent fc36e66af4
commit 6bb91f3b6e
10 changed files with 128 additions and 67 deletions

View file

@ -836,7 +836,7 @@ _io.FileIO.write
b: Py_buffer
/
Write bytes b to file, return number written.
Write buffer b to file, return number of bytes written.
Only makes one system call, so not all of the data may be written.
The number of bytes actually written is returned. In non-blocking mode,
@ -845,7 +845,7 @@ returns None if the write would block.
static PyObject *
_io_FileIO_write_impl(fileio *self, Py_buffer *b)
/*[clinic end generated code: output=b4059db3d363a2f7 input=ffbd8834f447ac31]*/
/*[clinic end generated code: output=b4059db3d363a2f7 input=6e7908b36f0ce74f]*/
{
Py_ssize_t n;
int err;