Issue #22854: Clarify documentation about UnsupportedOperation and add tests

Also change BufferedReader.writable() and BufferedWriter.readable() to always
return False.
This commit is contained in:
Martin Panter 2016-03-31 07:21:56 +00:00
parent 8dc2ec1513
commit 754aab28ed
6 changed files with 130 additions and 35 deletions

View file

@ -2398,7 +2398,6 @@ static PyMethodDef bufferedreader_methods[] = {
{"close", (PyCFunction)buffered_close, METH_NOARGS},
{"seekable", (PyCFunction)buffered_seekable, METH_NOARGS},
{"readable", (PyCFunction)buffered_readable, METH_NOARGS},
{"writable", (PyCFunction)buffered_writable, METH_NOARGS},
{"fileno", (PyCFunction)buffered_fileno, METH_NOARGS},
{"isatty", (PyCFunction)buffered_isatty, METH_NOARGS},
{"_dealloc_warn", (PyCFunction)buffered_dealloc_warn, METH_O},
@ -2489,7 +2488,6 @@ static PyMethodDef bufferedwriter_methods[] = {
{"close", (PyCFunction)buffered_close, METH_NOARGS},
{"detach", (PyCFunction)buffered_detach, METH_NOARGS},
{"seekable", (PyCFunction)buffered_seekable, METH_NOARGS},
{"readable", (PyCFunction)buffered_readable, METH_NOARGS},
{"writable", (PyCFunction)buffered_writable, METH_NOARGS},
{"fileno", (PyCFunction)buffered_fileno, METH_NOARGS},
{"isatty", (PyCFunction)buffered_isatty, METH_NOARGS},

View file

@ -66,7 +66,7 @@ PyDoc_STRVAR(_io__IOBase_seekable__doc__,
"\n"
"Return whether object supports random access.\n"
"\n"
"If False, seek(), tell() and truncate() will raise UnsupportedOperation.\n"
"If False, seek(), tell() and truncate() will raise OSError.\n"
"This method may need to do a test seek().");
#define _IO__IOBASE_SEEKABLE_METHODDEF \
@ -87,7 +87,7 @@ PyDoc_STRVAR(_io__IOBase_readable__doc__,
"\n"
"Return whether object was opened for reading.\n"
"\n"
"If False, read() will raise UnsupportedOperation.");
"If False, read() will raise OSError.");
#define _IO__IOBASE_READABLE_METHODDEF \
{"readable", (PyCFunction)_io__IOBase_readable, METH_NOARGS, _io__IOBase_readable__doc__},
@ -107,7 +107,7 @@ PyDoc_STRVAR(_io__IOBase_writable__doc__,
"\n"
"Return whether object was opened for writing.\n"
"\n"
"If False, write() will raise UnsupportedOperation.");
"If False, write() will raise OSError.");
#define _IO__IOBASE_WRITABLE_METHODDEF \
{"writable", (PyCFunction)_io__IOBase_writable, METH_NOARGS, _io__IOBase_writable__doc__},
@ -127,7 +127,7 @@ PyDoc_STRVAR(_io__IOBase_fileno__doc__,
"\n"
"Returns underlying file descriptor if one exists.\n"
"\n"
"An IOError is raised if the IO object does not use a file descriptor.");
"OSError is raised if the IO object does not use a file descriptor.");
#define _IO__IOBASE_FILENO_METHODDEF \
{"fileno", (PyCFunction)_io__IOBase_fileno, METH_NOARGS, _io__IOBase_fileno__doc__},
@ -276,4 +276,4 @@ _io__RawIOBase_readall(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return _io__RawIOBase_readall_impl(self);
}
/*[clinic end generated code: output=fe034152b6884e65 input=a9049054013a1b77]*/
/*[clinic end generated code: output=b874952f5cc248a4 input=a9049054013a1b77]*/

View file

@ -335,13 +335,13 @@ _io._IOBase.seekable
Return whether object supports random access.
If False, seek(), tell() and truncate() will raise UnsupportedOperation.
If False, seek(), tell() and truncate() will raise OSError.
This method may need to do a test seek().
[clinic start generated code]*/
static PyObject *
_io__IOBase_seekable_impl(PyObject *self)
/*[clinic end generated code: output=4c24c67f5f32a43d input=22676eebb81dcf1e]*/
/*[clinic end generated code: output=4c24c67f5f32a43d input=b976622f7fdf3063]*/
{
Py_RETURN_FALSE;
}
@ -368,12 +368,12 @@ _io._IOBase.readable
Return whether object was opened for reading.
If False, read() will raise UnsupportedOperation.
If False, read() will raise OSError.
[clinic start generated code]*/
static PyObject *
_io__IOBase_readable_impl(PyObject *self)
/*[clinic end generated code: output=e48089250686388b input=12fc3d8f6be46434]*/
/*[clinic end generated code: output=e48089250686388b input=285b3b866a0ec35f]*/
{
Py_RETURN_FALSE;
}
@ -401,12 +401,12 @@ _io._IOBase.writable
Return whether object was opened for writing.
If False, write() will raise UnsupportedOperation.
If False, write() will raise OSError.
[clinic start generated code]*/
static PyObject *
_io__IOBase_writable_impl(PyObject *self)
/*[clinic end generated code: output=406001d0985be14f input=c17a0bb6a8dfc590]*/
/*[clinic end generated code: output=406001d0985be14f input=9dcac18a013a05b5]*/
{
Py_RETURN_FALSE;
}
@ -456,12 +456,12 @@ _io._IOBase.fileno
Returns underlying file descriptor if one exists.
An IOError is raised if the IO object does not use a file descriptor.
OSError is raised if the IO object does not use a file descriptor.
[clinic start generated code]*/
static PyObject *
_io__IOBase_fileno_impl(PyObject *self)
/*[clinic end generated code: output=7cc0973f0f5f3b73 input=32773c5df4b7eede]*/
/*[clinic end generated code: output=7cc0973f0f5f3b73 input=4e37028947dc1cc8]*/
{
return iobase_unsupported("fileno");
}