https://github.com/python/cpython/commit/16292fcf9088c8fb4c771cc86fe51e7279577e79
commit: 16292fcf9088c8fb4c771cc86fe51e7279577e79
branch: main
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-09-24T20:23:07+03:00
summary:

gh-155496: Use Argument Clinic for more functions of the _io module (GH-155511)

files:
A Misc/NEWS.d/next/Library/2026-08-10-19-49-11.gh-issue-155496.B4rMR1.rst
M Lib/test/test_descr.py
M Lib/test/test_inspect/test_inspect.py
M Lib/test/test_io/test_textio.py
M Modules/_io/bufferedio.c
M Modules/_io/bytesio.c
M Modules/_io/clinic/bufferedio.c.h
M Modules/_io/clinic/bytesio.c.h
M Modules/_io/clinic/fileio.c.h
M Modules/_io/clinic/iobase.c.h
M Modules/_io/clinic/stringio.c.h
M Modules/_io/clinic/textio.c.h
M Modules/_io/clinic/winconsoleio.c.h
M Modules/_io/fileio.c
M Modules/_io/iobase.c
M Modules/_io/stringio.c
M Modules/_io/textio.c
M Modules/_io/winconsoleio.c

diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 7ac22455541fe2c..a6ebda5bf4e5df7 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -3405,7 +3405,7 @@ def test_descrdoc(self):
         from _io import FileIO
         def check(descr, what):
             self.assertEqual(descr.__doc__, what)
-        check(FileIO.closed, "True if the file is closed") # getset descriptor
+        check(FileIO.closed, "True if the file is closed.") # getset descriptor
         check(complex.real, "the real part of a complex number") # member 
descriptor
 
     def test_doc_descriptor(self):
diff --git a/Lib/test/test_inspect/test_inspect.py 
b/Lib/test/test_inspect/test_inspect.py
index a4381f2c0233954..d3760ac3c266a8f 100644
--- a/Lib/test/test_inspect/test_inspect.py
+++ b/Lib/test/test_inspect/test_inspect.py
@@ -6280,11 +6280,7 @@ def test_gc_module_has_signatures(self):
         self._test_module_has_signatures(gc, no_signature)
 
     def test_io_module_has_signatures(self):
-        methods_no_signature = {
-            'BufferedRWPair': {'read', 'peek', 'read1', 'readinto', 
'readinto1', 'write'},
-        }
-        self._test_module_has_signatures(io,
-                methods_no_signature=methods_no_signature)
+        self._test_module_has_signatures(io)
 
     def test_itertools_module_has_signatures(self):
         import itertools
diff --git a/Lib/test/test_io/test_textio.py b/Lib/test/test_io/test_textio.py
index a210b81d877dc1e..f9fb84101d4a2eb 100644
--- a/Lib/test/test_io/test_textio.py
+++ b/Lib/test/test_io/test_textio.py
@@ -1458,13 +1458,13 @@ def test_chunk_size(self):
             t._CHUNK_SIZE = 0
         with self.assertRaises(TypeError):
             t._CHUNK_SIZE = 'x'
-        with self.assertRaises(ValueError):
+        with self.assertRaises(OverflowError):
             t._CHUNK_SIZE = sys.maxsize + 1
-        with self.assertRaises(ValueError):
+        with self.assertRaises(OverflowError):
             t._CHUNK_SIZE = -sys.maxsize - 2
-        with self.assertRaises(ValueError):
+        with self.assertRaises(OverflowError):
             t._CHUNK_SIZE = 2**1000
-        with self.assertRaises(ValueError):
+        with self.assertRaises(OverflowError):
             t._CHUNK_SIZE = -2**1000
         with self.assertRaisesRegex(AttributeError, 'cannot be deleted'):
             del t._CHUNK_SIZE
diff --git 
a/Misc/NEWS.d/next/Library/2026-08-10-19-49-11.gh-issue-155496.B4rMR1.rst 
b/Misc/NEWS.d/next/Library/2026-08-10-19-49-11.gh-issue-155496.B4rMR1.rst
new file mode 100644
index 000000000000000..75f0f987127b198
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-08-10-19-49-11.gh-issue-155496.B4rMR1.rst
@@ -0,0 +1,3 @@
+:meth:`io.RawIOBase.readinto` and :meth:`io.RawIOBase.write` now raise
+:exc:`TypeError` instead of :exc:`NotImplementedError`
+if they are called without the required argument.
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
index 5537947f6a51c11..2cc3774e75c9dad 100644
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -2333,94 +2333,143 @@ bufferedrwpair_dealloc(PyObject *op)
     Py_DECREF(tp);
 }
 
+/* Call the method of the underlying reader or writer.  The argument is
+   only passed if it is not NULL, so that the default of that method is
+   used otherwise. */
 static PyObject *
-_forward_call(buffered *self, PyObject *name, PyObject *args)
+_forward_call(buffered *self, PyObject *name, PyObject *arg)
 {
-    PyObject *func, *ret;
     if (self == NULL) {
         PyErr_SetString(PyExc_ValueError,
                         "I/O operation on uninitialized object");
         return NULL;
     }
 
-    func = PyObject_GetAttr((PyObject *)self, name);
-    if (func == NULL) {
-        PyErr_SetObject(PyExc_AttributeError, name);
-        return NULL;
+    if (arg == NULL) {
+        return PyObject_CallMethodNoArgs((PyObject *)self, name);
     }
-
-    ret = PyObject_CallObject(func, args);
-    Py_DECREF(func);
-    return ret;
+    return PyObject_CallMethodOneArg((PyObject *)self, name, arg);
 }
 
+/*[clinic input]
+_io.BufferedRWPair.read
+    size: object(c_default="NULL") = -1
+    /
+[clinic start generated code]*/
+
 static PyObject *
-bufferedrwpair_read(PyObject *op, PyObject *args)
+_io_BufferedRWPair_read_impl(rwpair *self, PyObject *size)
+/*[clinic end generated code: output=0668e3c5dbd3e93d input=eddb5e52aba9ebe5]*/
 {
-    rwpair *self = rwpair_CAST(op);
-    return _forward_call(self->reader, &_Py_ID(read), args);
+    return _forward_call(self->reader, &_Py_ID(read), size);
 }
 
+/*[clinic input]
+_io.BufferedRWPair.peek
+    size: object(c_default="NULL") = 0
+    /
+[clinic start generated code]*/
+
 static PyObject *
-bufferedrwpair_peek(PyObject *op, PyObject *args)
+_io_BufferedRWPair_peek_impl(rwpair *self, PyObject *size)
+/*[clinic end generated code: output=190a267bd694efa0 input=36af95964bebe355]*/
 {
-    rwpair *self = rwpair_CAST(op);
-    return _forward_call(self->reader, &_Py_ID(peek), args);
+    return _forward_call(self->reader, &_Py_ID(peek), size);
 }
 
+/*[clinic input]
+_io.BufferedRWPair.read1
+    size: object(c_default="NULL") = -1
+    /
+[clinic start generated code]*/
+
 static PyObject *
-bufferedrwpair_read1(PyObject *op, PyObject *args)
+_io_BufferedRWPair_read1_impl(rwpair *self, PyObject *size)
+/*[clinic end generated code: output=17ec19608f2bb825 input=9e94db423e490b58]*/
 {
-    rwpair *self = rwpair_CAST(op);
-    return _forward_call(self->reader, &_Py_ID(read1), args);
+    return _forward_call(self->reader, &_Py_ID(read1), size);
 }
 
+/*[clinic input]
+_io.BufferedRWPair.readinto
+    buffer: object
+    /
+[clinic start generated code]*/
+
 static PyObject *
-bufferedrwpair_readinto(PyObject *op, PyObject *args)
+_io_BufferedRWPair_readinto_impl(rwpair *self, PyObject *buffer)
+/*[clinic end generated code: output=16c86b071015f7a4 input=ccd86ce2666261f7]*/
 {
-    rwpair *self = rwpair_CAST(op);
-    return _forward_call(self->reader, &_Py_ID(readinto), args);
+    return _forward_call(self->reader, &_Py_ID(readinto), buffer);
 }
 
+/*[clinic input]
+_io.BufferedRWPair.readinto1
+    buffer: object
+    /
+[clinic start generated code]*/
+
 static PyObject *
-bufferedrwpair_readinto1(PyObject *op, PyObject *args)
+_io_BufferedRWPair_readinto1_impl(rwpair *self, PyObject *buffer)
+/*[clinic end generated code: output=f1577b6f54c2b02a input=613d9bf127f88a4a]*/
 {
-    rwpair *self = rwpair_CAST(op);
-    return _forward_call(self->reader, &_Py_ID(readinto1), args);
+    return _forward_call(self->reader, &_Py_ID(readinto1), buffer);
 }
 
+/*[clinic input]
+_io.BufferedRWPair.write
+    buffer: object
+    /
+[clinic start generated code]*/
+
 static PyObject *
-bufferedrwpair_write(PyObject *op, PyObject *args)
+_io_BufferedRWPair_write_impl(rwpair *self, PyObject *buffer)
+/*[clinic end generated code: output=6f7509a747410c68 input=66c602422e3ec36f]*/
 {
-    rwpair *self = rwpair_CAST(op);
-    return _forward_call(self->writer, &_Py_ID(write), args);
+    return _forward_call(self->writer, &_Py_ID(write), buffer);
 }
 
+/*[clinic input]
+_io.BufferedRWPair.flush
+[clinic start generated code]*/
+
 static PyObject *
-bufferedrwpair_flush(PyObject *op, PyObject *Py_UNUSED(dummy))
+_io_BufferedRWPair_flush_impl(rwpair *self)
+/*[clinic end generated code: output=0b2dcbe828718d6b input=e853da796ee61df1]*/
 {
-    rwpair *self = rwpair_CAST(op);
     return _forward_call(self->writer, &_Py_ID(flush), NULL);
 }
 
+/*[clinic input]
+_io.BufferedRWPair.readable
+[clinic start generated code]*/
+
 static PyObject *
-bufferedrwpair_readable(PyObject *op, PyObject *Py_UNUSED(dummy))
+_io_BufferedRWPair_readable_impl(rwpair *self)
+/*[clinic end generated code: output=615967d4aa58f122 input=0475ed73d0a3167f]*/
 {
-    rwpair *self = rwpair_CAST(op);
     return _forward_call(self->reader, &_Py_ID(readable), NULL);
 }
 
+/*[clinic input]
+_io.BufferedRWPair.writable
+[clinic start generated code]*/
+
 static PyObject *
-bufferedrwpair_writable(PyObject *op, PyObject *Py_UNUSED(dummy))
+_io_BufferedRWPair_writable_impl(rwpair *self)
+/*[clinic end generated code: output=c5a43c84e0195c11 input=3cfd44fb4757082f]*/
 {
-    rwpair *self = rwpair_CAST(op);
     return _forward_call(self->writer, &_Py_ID(writable), NULL);
 }
 
+/*[clinic input]
+_io.BufferedRWPair.close
+[clinic start generated code]*/
+
 static PyObject *
-bufferedrwpair_close(PyObject *op, PyObject *Py_UNUSED(dummy))
+_io_BufferedRWPair_close_impl(rwpair *self)
+/*[clinic end generated code: output=5924ba5ecc78752a input=4087d69f2d8fc368]*/
 {
-    rwpair *self = rwpair_CAST(op);
     PyObject *exc = NULL;
     PyObject *ret = _forward_call(self->writer, &_Py_ID(close), NULL);
     if (ret == NULL) {
@@ -2437,10 +2486,14 @@ bufferedrwpair_close(PyObject *op, PyObject 
*Py_UNUSED(dummy))
     return ret;
 }
 
+/*[clinic input]
+_io.BufferedRWPair.isatty
+[clinic start generated code]*/
+
 static PyObject *
-bufferedrwpair_isatty(PyObject *op, PyObject *Py_UNUSED(dummy))
+_io_BufferedRWPair_isatty_impl(rwpair *self)
+/*[clinic end generated code: output=d017c621ed879cb7 input=92833e3d60586e14]*/
 {
-    rwpair *self = rwpair_CAST(op);
     PyObject *ret = _forward_call(self->writer, &_Py_ID(isatty), NULL);
 
     if (ret != Py_False) {
@@ -2452,10 +2505,15 @@ bufferedrwpair_isatty(PyObject *op, PyObject 
*Py_UNUSED(dummy))
     return _forward_call(self->reader, &_Py_ID(isatty), NULL);
 }
 
+/*[clinic input]
+@getter
+_io.BufferedRWPair.closed
+[clinic start generated code]*/
+
 static PyObject *
-bufferedrwpair_closed_get(PyObject *op, void *Py_UNUSED(dummy))
+_io_BufferedRWPair_closed_get_impl(rwpair *self)
+/*[clinic end generated code: output=4117400c74766f21 input=8248430ac54e5b25]*/
 {
-    rwpair *self = rwpair_CAST(op);
     if (self->writer == NULL) {
         PyErr_SetString(PyExc_RuntimeError,
                 "the BufferedRWPair object is being garbage-collected");
@@ -2670,20 +2728,20 @@ PyType_Spec _Py_bufferedwriter_spec = {
 };
 
 static PyMethodDef bufferedrwpair_methods[] = {
-    {"read", bufferedrwpair_read, METH_VARARGS},
-    {"peek", bufferedrwpair_peek, METH_VARARGS},
-    {"read1", bufferedrwpair_read1, METH_VARARGS},
-    {"readinto", bufferedrwpair_readinto, METH_VARARGS},
-    {"readinto1", bufferedrwpair_readinto1, METH_VARARGS},
+    _IO_BUFFEREDRWPAIR_READ_METHODDEF
+    _IO_BUFFEREDRWPAIR_PEEK_METHODDEF
+    _IO_BUFFEREDRWPAIR_READ1_METHODDEF
+    _IO_BUFFEREDRWPAIR_READINTO_METHODDEF
+    _IO_BUFFEREDRWPAIR_READINTO1_METHODDEF
 
-    {"write", bufferedrwpair_write, METH_VARARGS},
-    {"flush", bufferedrwpair_flush, METH_NOARGS},
+    _IO_BUFFEREDRWPAIR_WRITE_METHODDEF
+    _IO_BUFFEREDRWPAIR_FLUSH_METHODDEF
 
-    {"readable", bufferedrwpair_readable, METH_NOARGS},
-    {"writable", bufferedrwpair_writable, METH_NOARGS},
+    _IO_BUFFEREDRWPAIR_READABLE_METHODDEF
+    _IO_BUFFEREDRWPAIR_WRITABLE_METHODDEF
 
-    {"close", bufferedrwpair_close, METH_NOARGS},
-    {"isatty", bufferedrwpair_isatty, METH_NOARGS},
+    _IO_BUFFEREDRWPAIR_CLOSE_METHODDEF
+    _IO_BUFFEREDRWPAIR_ISATTY_METHODDEF
 
     {NULL, NULL}
 };
@@ -2695,7 +2753,7 @@ static PyMemberDef bufferedrwpair_members[] = {
 };
 
 static PyGetSetDef bufferedrwpair_getset[] = {
-    {"closed", bufferedrwpair_closed_get, NULL, NULL},
+    _IO_BUFFEREDRWPAIR_CLOSED_GETSETDEF
     {NULL}
 };
 
diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c
index b7c1555c2637dd5..ff9cc0f2166bd74 100644
--- a/Modules/_io/bytesio.c
+++ b/Modules/_io/bytesio.c
@@ -297,20 +297,19 @@ write_bytes_lock_held(bytesio *self, PyObject *b)
     return len;
 }
 
-static PyObject *
-bytesio_get_closed(PyObject *op, void *Py_UNUSED(closure))
+/*[clinic input]
+@critical_section
+@getter
+_io.BytesIO.closed -> bool
+
+True if the file is closed.
+[clinic start generated code]*/
+
+static int
+_io_BytesIO_closed_get_impl(bytesio *self)
+/*[clinic end generated code: output=7cdc647cc7a71683 input=0687f923344225ee]*/
 {
-    PyObject *ret;
-    bytesio *self = bytesio_CAST(op);
-    Py_BEGIN_CRITICAL_SECTION(self);
-    if (self->buf == NULL) {
-        ret = Py_True;
-    }
-    else {
-        ret = Py_False;
-    }
-    Py_END_CRITICAL_SECTION();
-    return ret;
+    return self->buf == NULL;
 }
 
 /*[clinic input]
@@ -950,54 +949,55 @@ _io_BytesIO_close_impl(bytesio *self)
    function to use the efficient instance representation of PEP 307.
  */
 
- static PyObject *
- bytesio_getstate_lock_held(PyObject *op)
- {
-     _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op);
-
-     bytesio *self = bytesio_CAST(op);
-     PyObject *initvalue = _io_BytesIO_getvalue_impl(self);
-     PyObject *dict;
-     PyObject *state;
-
-     if (initvalue == NULL)
-         return NULL;
-     if (self->dict == NULL) {
-         dict = Py_NewRef(Py_None);
-     }
-     else {
-         dict = PyDict_Copy(self->dict);
-         if (dict == NULL) {
-             Py_DECREF(initvalue);
-             return NULL;
-         }
-     }
-
-     state = Py_BuildValue("(OnN)", initvalue, self->pos, dict);
-     Py_DECREF(initvalue);
-     return state;
-}
+
+/*[clinic input]
+@critical_section
+_io.BytesIO.__getstate__
+[clinic start generated code]*/
 
 static PyObject *
-bytesio_getstate(PyObject *op, PyObject *Py_UNUSED(dummy))
+_io_BytesIO___getstate___impl(bytesio *self)
+/*[clinic end generated code: output=4a776270c8443b85 input=f41e5bc9731475c4]*/
 {
-    PyObject *ret;
-    Py_BEGIN_CRITICAL_SECTION(op);
-    ret = bytesio_getstate_lock_held(op);
-    Py_END_CRITICAL_SECTION();
-    return ret;
+    PyObject *initvalue = _io_BytesIO_getvalue_impl(self);
+    PyObject *dict;
+    PyObject *state;
+
+    if (initvalue == NULL)
+        return NULL;
+    if (self->dict == NULL) {
+        dict = Py_NewRef(Py_None);
+    }
+    else {
+        dict = PyDict_Copy(self->dict);
+        if (dict == NULL) {
+            Py_DECREF(initvalue);
+            return NULL;
+        }
+    }
+
+    state = Py_BuildValue("(OnN)", initvalue, self->pos, dict);
+    Py_DECREF(initvalue);
+    return state;
 }
 
+
+/*[clinic input]
+@critical_section
+_io.BytesIO.__setstate__
+
+    state: object
+    /
+[clinic start generated code]*/
+
 static PyObject *
-bytesio_setstate_lock_held(PyObject *op, PyObject *state)
+_io_BytesIO___setstate___impl(bytesio *self, PyObject *state)
+/*[clinic end generated code: output=3605abdec171bb98 input=82a189599ba75083]*/
 {
-    _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op);
-
     PyObject *result;
     PyObject *position_obj;
     PyObject *dict;
     Py_ssize_t pos;
-    bytesio *self = bytesio_CAST(op);
 
     assert(state != NULL);
 
@@ -1068,16 +1068,6 @@ bytesio_setstate_lock_held(PyObject *op, PyObject *state)
     Py_RETURN_NONE;
 }
 
-static PyObject *
-bytesio_setstate(PyObject *op, PyObject *state)
-{
-    PyObject *ret;
-    Py_BEGIN_CRITICAL_SECTION(op);
-    ret = bytesio_setstate_lock_held(op, state);
-    Py_END_CRITICAL_SECTION();
-    return ret;
-}
-
 static void
 bytesio_dealloc(PyObject *op)
 {
@@ -1159,12 +1149,18 @@ _io_BytesIO___init___impl(bytesio *self, PyObject 
*initvalue)
     return 0;
 }
 
+
+/*[clinic input]
+@critical_section
+_io.BytesIO.__sizeof__
+
+Size of object in memory, in bytes.
+[clinic start generated code]*/
+
 static PyObject *
-bytesio_sizeof_lock_held(PyObject *op)
+_io_BytesIO___sizeof___impl(bytesio *self)
+/*[clinic end generated code: output=f61b601bd055c4de input=6f01c36e6ff64c17]*/
 {
-    _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op);
-
-    bytesio *self = bytesio_CAST(op);
     size_t res = _PyObject_SIZE(Py_TYPE(self));
     if (self->buf && !SHARED_BUF(self)) {
         size_t s = _PySys_GetSizeOf(self->buf);
@@ -1176,16 +1172,6 @@ bytesio_sizeof_lock_held(PyObject *op)
     return PyLong_FromSize_t(res);
 }
 
-static PyObject *
-bytesio_sizeof(PyObject *op, PyObject *Py_UNUSED(dummy))
-{
-    PyObject *ret;
-    Py_BEGIN_CRITICAL_SECTION(op);
-    ret = bytesio_sizeof_lock_held(op);
-    Py_END_CRITICAL_SECTION();
-    return ret;
-}
-
 static int
 bytesio_traverse(PyObject *op, visitproc visit, void *arg)
 {
@@ -1213,8 +1199,7 @@ bytesio_clear(PyObject *op)
 #undef clinic_state
 
 static PyGetSetDef bytesio_getsetlist[] = {
-    {"closed",  bytesio_get_closed, NULL,
-     "True if the file is closed."},
+    _IO_BYTESIO_CLOSED_GETSETDEF
     {NULL},            /* sentinel */
 };
 
@@ -1238,9 +1223,9 @@ static struct PyMethodDef bytesio_methods[] = {
     _IO_BYTESIO_GETVALUE_METHODDEF
     _IO_BYTESIO_SEEK_METHODDEF
     _IO_BYTESIO_TRUNCATE_METHODDEF
-    {"__getstate__",  bytesio_getstate,  METH_NOARGS, NULL},
-    {"__setstate__",  bytesio_setstate,  METH_O, NULL},
-    {"__sizeof__", bytesio_sizeof,     METH_NOARGS, NULL},
+    _IO_BYTESIO___GETSTATE___METHODDEF
+    _IO_BYTESIO___SETSTATE___METHODDEF
+    _IO_BYTESIO___SIZEOF___METHODDEF
     {NULL, NULL}        /* sentinel */
 };
 
diff --git a/Modules/_io/clinic/bufferedio.c.h 
b/Modules/_io/clinic/bufferedio.c.h
index 3ca28c5a390736b..7575be251273f0d 100644
--- a/Modules/_io/clinic/bufferedio.c.h
+++ b/Modules/_io/clinic/bufferedio.c.h
@@ -1156,6 +1156,256 @@ _io_BufferedRWPair___init__(PyObject *self, PyObject 
*args, PyObject *kwargs)
     return return_value;
 }
 
+PyDoc_STRVAR(_io_BufferedRWPair_read__doc__,
+"read($self, size=-1, /)\n"
+"--\n"
+"\n");
+
+#define _IO_BUFFEREDRWPAIR_READ_METHODDEF    \
+    {"read", _PyCFunction_CAST(_io_BufferedRWPair_read), METH_FASTCALL, 
_io_BufferedRWPair_read__doc__},
+
+static PyObject *
+_io_BufferedRWPair_read_impl(rwpair *self, PyObject *size);
+
+static PyObject *
+_io_BufferedRWPair_read(PyObject *self, PyObject *const *args, Py_ssize_t 
nargs)
+{
+    PyObject *return_value = NULL;
+    PyObject *size = NULL;
+
+    if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
+        goto exit;
+    }
+    if (nargs < 1) {
+        goto skip_optional;
+    }
+    size = args[0];
+skip_optional:
+    return_value = _io_BufferedRWPair_read_impl((rwpair *)self, size);
+
+exit:
+    return return_value;
+}
+
+PyDoc_STRVAR(_io_BufferedRWPair_peek__doc__,
+"peek($self, size=0, /)\n"
+"--\n"
+"\n");
+
+#define _IO_BUFFEREDRWPAIR_PEEK_METHODDEF    \
+    {"peek", _PyCFunction_CAST(_io_BufferedRWPair_peek), METH_FASTCALL, 
_io_BufferedRWPair_peek__doc__},
+
+static PyObject *
+_io_BufferedRWPair_peek_impl(rwpair *self, PyObject *size);
+
+static PyObject *
+_io_BufferedRWPair_peek(PyObject *self, PyObject *const *args, Py_ssize_t 
nargs)
+{
+    PyObject *return_value = NULL;
+    PyObject *size = NULL;
+
+    if (!_PyArg_CheckPositional("peek", nargs, 0, 1)) {
+        goto exit;
+    }
+    if (nargs < 1) {
+        goto skip_optional;
+    }
+    size = args[0];
+skip_optional:
+    return_value = _io_BufferedRWPair_peek_impl((rwpair *)self, size);
+
+exit:
+    return return_value;
+}
+
+PyDoc_STRVAR(_io_BufferedRWPair_read1__doc__,
+"read1($self, size=-1, /)\n"
+"--\n"
+"\n");
+
+#define _IO_BUFFEREDRWPAIR_READ1_METHODDEF    \
+    {"read1", _PyCFunction_CAST(_io_BufferedRWPair_read1), METH_FASTCALL, 
_io_BufferedRWPair_read1__doc__},
+
+static PyObject *
+_io_BufferedRWPair_read1_impl(rwpair *self, PyObject *size);
+
+static PyObject *
+_io_BufferedRWPair_read1(PyObject *self, PyObject *const *args, Py_ssize_t 
nargs)
+{
+    PyObject *return_value = NULL;
+    PyObject *size = NULL;
+
+    if (!_PyArg_CheckPositional("read1", nargs, 0, 1)) {
+        goto exit;
+    }
+    if (nargs < 1) {
+        goto skip_optional;
+    }
+    size = args[0];
+skip_optional:
+    return_value = _io_BufferedRWPair_read1_impl((rwpair *)self, size);
+
+exit:
+    return return_value;
+}
+
+PyDoc_STRVAR(_io_BufferedRWPair_readinto__doc__,
+"readinto($self, buffer, /)\n"
+"--\n"
+"\n");
+
+#define _IO_BUFFEREDRWPAIR_READINTO_METHODDEF    \
+    {"readinto", (PyCFunction)_io_BufferedRWPair_readinto, METH_O, 
_io_BufferedRWPair_readinto__doc__},
+
+static PyObject *
+_io_BufferedRWPair_readinto_impl(rwpair *self, PyObject *buffer);
+
+static PyObject *
+_io_BufferedRWPair_readinto(PyObject *self, PyObject *buffer)
+{
+    PyObject *return_value = NULL;
+
+    return_value = _io_BufferedRWPair_readinto_impl((rwpair *)self, buffer);
+
+    return return_value;
+}
+
+PyDoc_STRVAR(_io_BufferedRWPair_readinto1__doc__,
+"readinto1($self, buffer, /)\n"
+"--\n"
+"\n");
+
+#define _IO_BUFFEREDRWPAIR_READINTO1_METHODDEF    \
+    {"readinto1", (PyCFunction)_io_BufferedRWPair_readinto1, METH_O, 
_io_BufferedRWPair_readinto1__doc__},
+
+static PyObject *
+_io_BufferedRWPair_readinto1_impl(rwpair *self, PyObject *buffer);
+
+static PyObject *
+_io_BufferedRWPair_readinto1(PyObject *self, PyObject *buffer)
+{
+    PyObject *return_value = NULL;
+
+    return_value = _io_BufferedRWPair_readinto1_impl((rwpair *)self, buffer);
+
+    return return_value;
+}
+
+PyDoc_STRVAR(_io_BufferedRWPair_write__doc__,
+"write($self, buffer, /)\n"
+"--\n"
+"\n");
+
+#define _IO_BUFFEREDRWPAIR_WRITE_METHODDEF    \
+    {"write", (PyCFunction)_io_BufferedRWPair_write, METH_O, 
_io_BufferedRWPair_write__doc__},
+
+static PyObject *
+_io_BufferedRWPair_write_impl(rwpair *self, PyObject *buffer);
+
+static PyObject *
+_io_BufferedRWPair_write(PyObject *self, PyObject *buffer)
+{
+    PyObject *return_value = NULL;
+
+    return_value = _io_BufferedRWPair_write_impl((rwpair *)self, buffer);
+
+    return return_value;
+}
+
+PyDoc_STRVAR(_io_BufferedRWPair_flush__doc__,
+"flush($self, /)\n"
+"--\n"
+"\n");
+
+#define _IO_BUFFEREDRWPAIR_FLUSH_METHODDEF    \
+    {"flush", (PyCFunction)_io_BufferedRWPair_flush, METH_NOARGS, 
_io_BufferedRWPair_flush__doc__},
+
+static PyObject *
+_io_BufferedRWPair_flush_impl(rwpair *self);
+
+static PyObject *
+_io_BufferedRWPair_flush(PyObject *self, PyObject *Py_UNUSED(ignored))
+{
+    return _io_BufferedRWPair_flush_impl((rwpair *)self);
+}
+
+PyDoc_STRVAR(_io_BufferedRWPair_readable__doc__,
+"readable($self, /)\n"
+"--\n"
+"\n");
+
+#define _IO_BUFFEREDRWPAIR_READABLE_METHODDEF    \
+    {"readable", (PyCFunction)_io_BufferedRWPair_readable, METH_NOARGS, 
_io_BufferedRWPair_readable__doc__},
+
+static PyObject *
+_io_BufferedRWPair_readable_impl(rwpair *self);
+
+static PyObject *
+_io_BufferedRWPair_readable(PyObject *self, PyObject *Py_UNUSED(ignored))
+{
+    return _io_BufferedRWPair_readable_impl((rwpair *)self);
+}
+
+PyDoc_STRVAR(_io_BufferedRWPair_writable__doc__,
+"writable($self, /)\n"
+"--\n"
+"\n");
+
+#define _IO_BUFFEREDRWPAIR_WRITABLE_METHODDEF    \
+    {"writable", (PyCFunction)_io_BufferedRWPair_writable, METH_NOARGS, 
_io_BufferedRWPair_writable__doc__},
+
+static PyObject *
+_io_BufferedRWPair_writable_impl(rwpair *self);
+
+static PyObject *
+_io_BufferedRWPair_writable(PyObject *self, PyObject *Py_UNUSED(ignored))
+{
+    return _io_BufferedRWPair_writable_impl((rwpair *)self);
+}
+
+PyDoc_STRVAR(_io_BufferedRWPair_close__doc__,
+"close($self, /)\n"
+"--\n"
+"\n");
+
+#define _IO_BUFFEREDRWPAIR_CLOSE_METHODDEF    \
+    {"close", (PyCFunction)_io_BufferedRWPair_close, METH_NOARGS, 
_io_BufferedRWPair_close__doc__},
+
+static PyObject *
+_io_BufferedRWPair_close_impl(rwpair *self);
+
+static PyObject *
+_io_BufferedRWPair_close(PyObject *self, PyObject *Py_UNUSED(ignored))
+{
+    return _io_BufferedRWPair_close_impl((rwpair *)self);
+}
+
+PyDoc_STRVAR(_io_BufferedRWPair_isatty__doc__,
+"isatty($self, /)\n"
+"--\n"
+"\n");
+
+#define _IO_BUFFEREDRWPAIR_ISATTY_METHODDEF    \
+    {"isatty", (PyCFunction)_io_BufferedRWPair_isatty, METH_NOARGS, 
_io_BufferedRWPair_isatty__doc__},
+
+static PyObject *
+_io_BufferedRWPair_isatty_impl(rwpair *self);
+
+static PyObject *
+_io_BufferedRWPair_isatty(PyObject *self, PyObject *Py_UNUSED(ignored))
+{
+    return _io_BufferedRWPair_isatty_impl((rwpair *)self);
+}
+
+static PyObject *
+_io_BufferedRWPair_closed_get_impl(rwpair *self);
+
+static PyObject *
+_io_BufferedRWPair_closed_get(PyObject *self, void *Py_UNUSED(context))
+{
+    return _io_BufferedRWPair_closed_get_impl((rwpair *)self);
+}
+
 PyDoc_STRVAR(_io_BufferedRandom___init____doc__,
 "BufferedRandom(raw, buffer_size=DEFAULT_BUFFER_SIZE)\n"
 "--\n"
@@ -1241,4 +1491,6 @@ _io_BufferedRandom___init__(PyObject *self, PyObject 
*args, PyObject *kwargs)
 
 #define _IO__BUFFERED_MODE_GETSETDEF {"mode", (getter)_io__Buffered_mode_get, 
(setter)NULL, NULL},
 
-/*[clinic end generated code: output=cac02514680dfc60 input=a9049054013a1b77]*/
+#define _IO_BUFFEREDRWPAIR_CLOSED_GETSETDEF {"closed", 
(getter)_io_BufferedRWPair_closed_get, (setter)NULL, NULL},
+
+/*[clinic end generated code: output=6fc10169822af939 input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/bytesio.c.h b/Modules/_io/clinic/bytesio.c.h
index a0159c063b58591..afdb60e506a2ce2 100644
--- a/Modules/_io/clinic/bytesio.c.h
+++ b/Modules/_io/clinic/bytesio.c.h
@@ -10,6 +10,30 @@ preserve
 #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
 #include "pycore_modsupport.h"    // _PyArg_CheckPositional()
 
+PyDoc_STRVAR(_io_BytesIO_closed__doc__,
+"True if the file is closed.");
+
+static int
+_io_BytesIO_closed_get_impl(bytesio *self);
+
+static PyObject *
+_io_BytesIO_closed_get(PyObject *self, void *Py_UNUSED(context))
+{
+    PyObject *return_value = NULL;
+    int _return_value;
+
+    Py_BEGIN_CRITICAL_SECTION(self);
+    _return_value = _io_BytesIO_closed_get_impl((bytesio *)self);
+    Py_END_CRITICAL_SECTION();
+    if ((_return_value == -1) && PyErr_Occurred()) {
+        goto exit;
+    }
+    return_value = PyBool_FromLong((long)_return_value);
+
+exit:
+    return return_value;
+}
+
 PyDoc_STRVAR(_io_BytesIO_readable__doc__,
 "readable($self, /)\n"
 "--\n"
@@ -621,6 +645,52 @@ _io_BytesIO_close(PyObject *self, PyObject 
*Py_UNUSED(ignored))
     return return_value;
 }
 
+PyDoc_STRVAR(_io_BytesIO___getstate____doc__,
+"__getstate__($self, /)\n"
+"--\n"
+"\n");
+
+#define _IO_BYTESIO___GETSTATE___METHODDEF    \
+    {"__getstate__", (PyCFunction)_io_BytesIO___getstate__, METH_NOARGS, 
_io_BytesIO___getstate____doc__},
+
+static PyObject *
+_io_BytesIO___getstate___impl(bytesio *self);
+
+static PyObject *
+_io_BytesIO___getstate__(PyObject *self, PyObject *Py_UNUSED(ignored))
+{
+    PyObject *return_value = NULL;
+
+    Py_BEGIN_CRITICAL_SECTION(self);
+    return_value = _io_BytesIO___getstate___impl((bytesio *)self);
+    Py_END_CRITICAL_SECTION();
+
+    return return_value;
+}
+
+PyDoc_STRVAR(_io_BytesIO___setstate____doc__,
+"__setstate__($self, state, /)\n"
+"--\n"
+"\n");
+
+#define _IO_BYTESIO___SETSTATE___METHODDEF    \
+    {"__setstate__", (PyCFunction)_io_BytesIO___setstate__, METH_O, 
_io_BytesIO___setstate____doc__},
+
+static PyObject *
+_io_BytesIO___setstate___impl(bytesio *self, PyObject *state);
+
+static PyObject *
+_io_BytesIO___setstate__(PyObject *self, PyObject *state)
+{
+    PyObject *return_value = NULL;
+
+    Py_BEGIN_CRITICAL_SECTION(self);
+    return_value = _io_BytesIO___setstate___impl((bytesio *)self, state);
+    Py_END_CRITICAL_SECTION();
+
+    return return_value;
+}
+
 PyDoc_STRVAR(_io_BytesIO___init____doc__,
 "BytesIO(initial_bytes=b\'\')\n"
 "--\n"
@@ -684,4 +754,30 @@ _io_BytesIO___init__(PyObject *self, PyObject *args, 
PyObject *kwargs)
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=b5e625e31b2a82f0 input=a9049054013a1b77]*/
+
+PyDoc_STRVAR(_io_BytesIO___sizeof____doc__,
+"__sizeof__($self, /)\n"
+"--\n"
+"\n"
+"Size of object in memory, in bytes.");
+
+#define _IO_BYTESIO___SIZEOF___METHODDEF    \
+    {"__sizeof__", (PyCFunction)_io_BytesIO___sizeof__, METH_NOARGS, 
_io_BytesIO___sizeof____doc__},
+
+static PyObject *
+_io_BytesIO___sizeof___impl(bytesio *self);
+
+static PyObject *
+_io_BytesIO___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored))
+{
+    PyObject *return_value = NULL;
+
+    Py_BEGIN_CRITICAL_SECTION(self);
+    return_value = _io_BytesIO___sizeof___impl((bytesio *)self);
+    Py_END_CRITICAL_SECTION();
+
+    return return_value;
+}
+#define _IO_BYTESIO_CLOSED_GETSETDEF {"closed", 
(getter)_io_BytesIO_closed_get, (setter)NULL, _io_BytesIO_closed__doc__},
+
+/*[clinic end generated code: output=a3dc7a416dae6ae9 input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/fileio.c.h b/Modules/_io/clinic/fileio.c.h
index 890b6bc3fac9d55..207ad64fe62f958 100644
--- a/Modules/_io/clinic/fileio.c.h
+++ b/Modules/_io/clinic/fileio.c.h
@@ -9,6 +9,27 @@ preserve
 #include "pycore_abstract.h"      // _Py_convert_optional_to_ssize_t()
 #include "pycore_modsupport.h"    // _PyArg_UnpackKeywords()
 
+PyDoc_STRVAR(_io_FileIO__dealloc_warn__doc__,
+"_dealloc_warn($self, source, /)\n"
+"--\n"
+"\n");
+
+#define _IO_FILEIO__DEALLOC_WARN_METHODDEF    \
+    {"_dealloc_warn", (PyCFunction)_io_FileIO__dealloc_warn, METH_O, 
_io_FileIO__dealloc_warn__doc__},
+
+static PyObject *
+_io_FileIO__dealloc_warn_impl(fileio *self, PyObject *source);
+
+static PyObject *
+_io_FileIO__dealloc_warn(PyObject *self, PyObject *source)
+{
+    PyObject *return_value = NULL;
+
+    return_value = _io_FileIO__dealloc_warn_impl((fileio *)self, source);
+
+    return return_value;
+}
+
 PyDoc_STRVAR(_io_FileIO_close__doc__,
 "close($self, /)\n"
 "--\n"
@@ -550,7 +571,110 @@ _io_FileIO_isatty(PyObject *self, PyObject 
*Py_UNUSED(ignored))
     return _io_FileIO_isatty_impl((fileio *)self);
 }
 
+PyDoc_STRVAR(_io_FileIO__isatty_open_only__doc__,
+"_isatty_open_only($self, /)\n"
+"--\n"
+"\n");
+
+#define _IO_FILEIO__ISATTY_OPEN_ONLY_METHODDEF    \
+    {"_isatty_open_only", (PyCFunction)_io_FileIO__isatty_open_only, 
METH_NOARGS, _io_FileIO__isatty_open_only__doc__},
+
+static PyObject *
+_io_FileIO__isatty_open_only_impl(fileio *self);
+
+static PyObject *
+_io_FileIO__isatty_open_only(PyObject *self, PyObject *Py_UNUSED(ignored))
+{
+    return _io_FileIO__isatty_open_only_impl((fileio *)self);
+}
+
+PyDoc_STRVAR(_io_FileIO_closed__doc__,
+"True if the file is closed.");
+
+static int
+_io_FileIO_closed_get_impl(fileio *self);
+
+static PyObject *
+_io_FileIO_closed_get(PyObject *self, void *Py_UNUSED(context))
+{
+    PyObject *return_value = NULL;
+    int _return_value;
+
+    _return_value = _io_FileIO_closed_get_impl((fileio *)self);
+    if ((_return_value == -1) && PyErr_Occurred()) {
+        goto exit;
+    }
+    return_value = PyBool_FromLong((long)_return_value);
+
+exit:
+    return return_value;
+}
+
+PyDoc_STRVAR(_io_FileIO_closefd__doc__,
+"True if the file descriptor will be closed by close().");
+
+static int
+_io_FileIO_closefd_get_impl(fileio *self);
+
+static PyObject *
+_io_FileIO_closefd_get(PyObject *self, void *Py_UNUSED(context))
+{
+    PyObject *return_value = NULL;
+    int _return_value;
+
+    _return_value = _io_FileIO_closefd_get_impl((fileio *)self);
+    if ((_return_value == -1) && PyErr_Occurred()) {
+        goto exit;
+    }
+    return_value = PyBool_FromLong((long)_return_value);
+
+exit:
+    return return_value;
+}
+
+PyDoc_STRVAR(_io_FileIO_mode__doc__,
+"String giving the file mode.");
+
+static PyObject *
+_io_FileIO_mode_get_impl(fileio *self);
+
+static PyObject *
+_io_FileIO_mode_get(PyObject *self, void *Py_UNUSED(context))
+{
+    return _io_FileIO_mode_get_impl((fileio *)self);
+}
+
+PyDoc_STRVAR(_io_FileIO__blksize__doc__,
+"Stat st_blksize if available.");
+
+static long
+_io_FileIO__blksize_get_impl(fileio *self);
+
+static PyObject *
+_io_FileIO__blksize_get(PyObject *self, void *Py_UNUSED(context))
+{
+    PyObject *return_value = NULL;
+    long _return_value;
+
+    _return_value = _io_FileIO__blksize_get_impl((fileio *)self);
+    if ((_return_value == -1) && PyErr_Occurred()) {
+        goto exit;
+    }
+    return_value = PyLong_FromLong(_return_value);
+
+exit:
+    return return_value;
+}
+
 #ifndef _IO_FILEIO_TRUNCATE_METHODDEF
     #define _IO_FILEIO_TRUNCATE_METHODDEF
 #endif /* !defined(_IO_FILEIO_TRUNCATE_METHODDEF) */
-/*[clinic end generated code: output=453d584e2e72f986 input=a9049054013a1b77]*/
+#define _IO_FILEIO_CLOSED_GETSETDEF {"closed", (getter)_io_FileIO_closed_get, 
(setter)NULL, _io_FileIO_closed__doc__},
+
+#define _IO_FILEIO_CLOSEFD_GETSETDEF {"closefd", 
(getter)_io_FileIO_closefd_get, (setter)NULL, _io_FileIO_closefd__doc__},
+
+#define _IO_FILEIO_MODE_GETSETDEF {"mode", (getter)_io_FileIO_mode_get, 
(setter)NULL, _io_FileIO_mode__doc__},
+
+#define _IO_FILEIO__BLKSIZE_GETSETDEF {"_blksize", 
(getter)_io_FileIO__blksize_get, (setter)NULL, _io_FileIO__blksize__doc__},
+
+/*[clinic end generated code: output=d0a63950bc345c85 input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/iobase.c.h b/Modules/_io/clinic/iobase.c.h
index e4438c26431aa8e..3020cf03972ee9f 100644
--- a/Modules/_io/clinic/iobase.c.h
+++ b/Modules/_io/clinic/iobase.c.h
@@ -171,6 +171,96 @@ _io__IOBase_flush(PyObject *self, PyObject 
*Py_UNUSED(ignored))
     return _io__IOBase_flush_impl(self);
 }
 
+PyDoc_STRVAR(_io__IOBase_closed__doc__,
+"True if the file is closed.");
+
+static int
+_io__IOBase_closed_get_impl(PyObject *self);
+
+static PyObject *
+_io__IOBase_closed_get(PyObject *self, void *Py_UNUSED(context))
+{
+    PyObject *return_value = NULL;
+    int _return_value;
+
+    _return_value = _io__IOBase_closed_get_impl(self);
+    if ((_return_value == -1) && PyErr_Occurred()) {
+        goto exit;
+    }
+    return_value = PyBool_FromLong((long)_return_value);
+
+exit:
+    return return_value;
+}
+
+PyDoc_STRVAR(_io__IOBase__checkClosed__doc__,
+"_checkClosed($self, /)\n"
+"--\n"
+"\n");
+
+#define _IO__IOBASE__CHECKCLOSED_METHODDEF    \
+    {"_checkClosed", (PyCFunction)_io__IOBase__checkClosed, METH_NOARGS, 
_io__IOBase__checkClosed__doc__},
+
+static PyObject *
+_io__IOBase__checkClosed_impl(PyObject *self);
+
+static PyObject *
+_io__IOBase__checkClosed(PyObject *self, PyObject *Py_UNUSED(ignored))
+{
+    return _io__IOBase__checkClosed_impl(self);
+}
+
+PyDoc_STRVAR(_io__IOBase__checkSeekable__doc__,
+"_checkSeekable($self, /)\n"
+"--\n"
+"\n");
+
+#define _IO__IOBASE__CHECKSEEKABLE_METHODDEF    \
+    {"_checkSeekable", (PyCFunction)_io__IOBase__checkSeekable, METH_NOARGS, 
_io__IOBase__checkSeekable__doc__},
+
+static PyObject *
+_io__IOBase__checkSeekable_impl(PyObject *self);
+
+static PyObject *
+_io__IOBase__checkSeekable(PyObject *self, PyObject *Py_UNUSED(ignored))
+{
+    return _io__IOBase__checkSeekable_impl(self);
+}
+
+PyDoc_STRVAR(_io__IOBase__checkReadable__doc__,
+"_checkReadable($self, /)\n"
+"--\n"
+"\n");
+
+#define _IO__IOBASE__CHECKREADABLE_METHODDEF    \
+    {"_checkReadable", (PyCFunction)_io__IOBase__checkReadable, METH_NOARGS, 
_io__IOBase__checkReadable__doc__},
+
+static PyObject *
+_io__IOBase__checkReadable_impl(PyObject *self);
+
+static PyObject *
+_io__IOBase__checkReadable(PyObject *self, PyObject *Py_UNUSED(ignored))
+{
+    return _io__IOBase__checkReadable_impl(self);
+}
+
+PyDoc_STRVAR(_io__IOBase__checkWritable__doc__,
+"_checkWritable($self, /)\n"
+"--\n"
+"\n");
+
+#define _IO__IOBASE__CHECKWRITABLE_METHODDEF    \
+    {"_checkWritable", (PyCFunction)_io__IOBase__checkWritable, METH_NOARGS, 
_io__IOBase__checkWritable__doc__},
+
+static PyObject *
+_io__IOBase__checkWritable_impl(PyObject *self);
+
+static PyObject *
+_io__IOBase__checkWritable(PyObject *self, PyObject *Py_UNUSED(ignored))
+{
+    return _io__IOBase__checkWritable_impl(self);
+}
+
 PyDoc_STRVAR(_io__IOBase_close__doc__,
 "close($self, /)\n"
 "--\n"
@@ -252,6 +342,55 @@ _io__IOBase_writable(PyObject *self, PyObject 
*Py_UNUSED(ignored))
     return _io__IOBase_writable_impl(self);
 }
 
+PyDoc_STRVAR(_io__IOBase___enter____doc__,
+"__enter__($self, /)\n"
+"--\n"
+"\n"
+"Context management protocol.  Returns the stream itself.");
+
+#define _IO__IOBASE___ENTER___METHODDEF    \
+    {"__enter__", (PyCFunction)_io__IOBase___enter__, METH_NOARGS, 
_io__IOBase___enter____doc__},
+
+static PyObject *
+_io__IOBase___enter___impl(PyObject *self);
+
+static PyObject *
+_io__IOBase___enter__(PyObject *self, PyObject *Py_UNUSED(ignored))
+{
+    return _io__IOBase___enter___impl(self);
+}
+
+PyDoc_STRVAR(_io__IOBase___exit____doc__,
+"__exit__($self, /, *args)\n"
+"--\n"
+"\n"
+"Context management protocol.  Calls close().");
+
+#define _IO__IOBASE___EXIT___METHODDEF    \
+    {"__exit__", _PyCFunction_CAST(_io__IOBase___exit__), METH_FASTCALL, 
_io__IOBase___exit____doc__},
+
+static PyObject *
+_io__IOBase___exit___impl(PyObject *self, PyObject *args);
+
+static PyObject *
+_io__IOBase___exit__(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
+{
+    PyObject *return_value = NULL;
+    PyObject *__clinic_args = NULL;
+
+    __clinic_args = PyTuple_FromArray(args, nargs);
+    if (__clinic_args == NULL) {
+        goto exit;
+    }
+    return_value = _io__IOBase___exit___impl(self, __clinic_args);
+
+exit:
+    /* Cleanup for args */
+    Py_XDECREF(__clinic_args);
+
+    return return_value;
+}
+
 PyDoc_STRVAR(_io__IOBase_fileno__doc__,
 "fileno($self, /)\n"
 "--\n"
@@ -445,4 +584,22 @@ _io__RawIOBase_readall(PyObject *self, PyObject 
*Py_UNUSED(ignored))
 {
     return _io__RawIOBase_readall_impl(self);
 }
-/*[clinic end generated code: output=28c06bb6db32c096 input=a9049054013a1b77]*/
+
+PyDoc_STRVAR(_io__RawIOBase_readinto__doc__,
+"readinto($self, buffer, /)\n"
+"--\n"
+"\n");
+
+#define _IO__RAWIOBASE_READINTO_METHODDEF    \
+    {"readinto", (PyCFunction)_io__RawIOBase_readinto, METH_O, 
_io__RawIOBase_readinto__doc__},
+
+PyDoc_STRVAR(_io__RawIOBase_write__doc__,
+"write($self, buffer, /)\n"
+"--\n"
+"\n");
+
+#define _IO__RAWIOBASE_WRITE_METHODDEF    \
+    {"write", (PyCFunction)_io__RawIOBase_write, METH_O, 
_io__RawIOBase_write__doc__},
+#define _IO__IOBASE_CLOSED_GETSETDEF {"closed", 
(getter)_io__IOBase_closed_get, (setter)NULL, _io__IOBase_closed__doc__},
+
+/*[clinic end generated code: output=fe3b46799e3cf0a9 input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/stringio.c.h b/Modules/_io/clinic/stringio.c.h
index e9c6c39dc64b049..66b7a57cdf93337 100644
--- a/Modules/_io/clinic/stringio.c.h
+++ b/Modules/_io/clinic/stringio.c.h
@@ -477,33 +477,45 @@ _io_StringIO___setstate__(PyObject *self, PyObject *state)
     return return_value;
 }
 
-static PyObject *
+static int
 _io_StringIO_closed_get_impl(stringio *self);
 
 static PyObject *
 _io_StringIO_closed_get(PyObject *self, void *Py_UNUSED(context))
 {
     PyObject *return_value = NULL;
+    int _return_value;
 
     Py_BEGIN_CRITICAL_SECTION(self);
-    return_value = _io_StringIO_closed_get_impl((stringio *)self);
+    _return_value = _io_StringIO_closed_get_impl((stringio *)self);
     Py_END_CRITICAL_SECTION();
+    if ((_return_value == -1) && PyErr_Occurred()) {
+        goto exit;
+    }
+    return_value = PyBool_FromLong((long)_return_value);
 
+exit:
     return return_value;
 }
 
-static PyObject *
+static int
 _io_StringIO_line_buffering_get_impl(stringio *self);
 
 static PyObject *
 _io_StringIO_line_buffering_get(PyObject *self, void *Py_UNUSED(context))
 {
     PyObject *return_value = NULL;
+    int _return_value;
 
     Py_BEGIN_CRITICAL_SECTION(self);
-    return_value = _io_StringIO_line_buffering_get_impl((stringio *)self);
+    _return_value = _io_StringIO_line_buffering_get_impl((stringio *)self);
     Py_END_CRITICAL_SECTION();
+    if ((_return_value == -1) && PyErr_Occurred()) {
+        goto exit;
+    }
+    return_value = PyBool_FromLong((long)_return_value);
 
+exit:
     return return_value;
 }
 
@@ -527,4 +539,4 @@ _io_StringIO_newlines_get(PyObject *self, void 
*Py_UNUSED(context))
 
 #define _IO_STRINGIO_NEWLINES_GETSETDEF {"newlines", 
(getter)_io_StringIO_newlines_get, (setter)NULL, NULL},
 
-/*[clinic end generated code: output=6fa0c0dd69543304 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=4100afa5e4f295d7 input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h
index f782ec197146636..a0cefdf3bc9a9e7 100644
--- a/Modules/_io/clinic/textio.c.h
+++ b/Modules/_io/clinic/textio.c.h
@@ -467,6 +467,15 @@ _io_IncrementalNewlineDecoder_reset(PyObject *self, 
PyObject *Py_UNUSED(ignored)
     return return_value;
 }
 
+static PyObject *
+_io_IncrementalNewlineDecoder_newlines_get_impl(nldecoder_object *self);
+
+static PyObject *
+_io_IncrementalNewlineDecoder_newlines_get(PyObject *self, void 
*Py_UNUSED(context))
+{
+    return _io_IncrementalNewlineDecoder_newlines_get_impl((nldecoder_object 
*)self);
+}
+
 PyDoc_STRVAR(_io_TextIOWrapper___init____doc__,
 "TextIOWrapper(buffer, encoding=None, errors=None, newline=None,\n"
 "              line_buffering=False, write_through=False)\n"
@@ -1200,29 +1209,35 @@ _io_TextIOWrapper_errors_get(PyObject *self, void 
*Py_UNUSED(context))
     return return_value;
 }
 
-static PyObject *
+static Py_ssize_t
 _io_TextIOWrapper__CHUNK_SIZE_get_impl(textio *self);
 
 static PyObject *
 _io_TextIOWrapper__CHUNK_SIZE_get(PyObject *self, void *Py_UNUSED(context))
 {
     PyObject *return_value = NULL;
+    Py_ssize_t _return_value;
 
     Py_BEGIN_CRITICAL_SECTION(self);
-    return_value = _io_TextIOWrapper__CHUNK_SIZE_get_impl((textio *)self);
+    _return_value = _io_TextIOWrapper__CHUNK_SIZE_get_impl((textio *)self);
     Py_END_CRITICAL_SECTION();
+    if ((_return_value == -1) && PyErr_Occurred()) {
+        goto exit;
+    }
+    return_value = PyLong_FromSsize_t(_return_value);
 
+exit:
     return return_value;
 }
 
 static int
-_io_TextIOWrapper__CHUNK_SIZE_set_impl(textio *self, PyObject *value);
+_io_TextIOWrapper__CHUNK_SIZE_set_impl(textio *self, Py_ssize_t value);
 
 static int
 _io_TextIOWrapper__CHUNK_SIZE_set(PyObject *self, PyObject *arg, void 
*Py_UNUSED(context))
 {
     int return_value = -1;
-    PyObject *value;
+    Py_ssize_t value;
 
     if (arg == NULL) {
         PyErr_Format(PyExc_AttributeError,
@@ -1230,11 +1245,23 @@ _io_TextIOWrapper__CHUNK_SIZE_set(PyObject *self, 
PyObject *arg, void *Py_UNUSED
                      Py_TYPE(self)->tp_name);
         return -1;
     }
-    value = arg;
+    {
+        Py_ssize_t ival = -1;
+        PyObject *iobj = _PyNumber_Index(arg);
+        if (iobj != NULL) {
+            ival = PyLong_AsSsize_t(iobj);
+            Py_DECREF(iobj);
+        }
+        if (ival == -1 && PyErr_Occurred()) {
+            goto exit;
+        }
+        value = ival;
+    }
     Py_BEGIN_CRITICAL_SECTION(self);
     return_value = _io_TextIOWrapper__CHUNK_SIZE_set_impl((textio *)self, 
value);
     Py_END_CRITICAL_SECTION();
 
+exit:
     return return_value;
 }
 
@@ -1258,6 +1285,8 @@ _io_TextIOWrapper_buffer_get(PyObject *self, void 
*Py_UNUSED(context))
 
 #define _IO__TEXTIOBASE_ERRORS_GETSETDEF {"errors", 
(getter)_io__TextIOBase_errors_get, (setter)NULL, 
_io__TextIOBase_errors__doc__},
 
+#define _IO_INCREMENTALNEWLINEDECODER_NEWLINES_GETSETDEF {"newlines", 
(getter)_io_IncrementalNewlineDecoder_newlines_get, (setter)NULL, NULL},
+
 #define _IO_TEXTIOWRAPPER_NAME_GETSETDEF {"name", 
(getter)_io_TextIOWrapper_name_get, (setter)NULL, NULL},
 
 #define _IO_TEXTIOWRAPPER_CLOSED_GETSETDEF {"closed", 
(getter)_io_TextIOWrapper_closed_get, (setter)NULL, NULL},
@@ -1270,4 +1299,4 @@ _io_TextIOWrapper_buffer_get(PyObject *self, void 
*Py_UNUSED(context))
 
 #define _IO_TEXTIOWRAPPER_BUFFER_GETSETDEF {"buffer", 
(getter)_io_TextIOWrapper_buffer_get, (setter)NULL, NULL},
 
-/*[clinic end generated code: output=72ad4f1b23cc606f input=a9049054013a1b77]*/
+/*[clinic end generated code: output=102ae91df6216de2 input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/winconsoleio.c.h 
b/Modules/_io/clinic/winconsoleio.c.h
index bd8073cd0af3f64..a0ebce1772ae903 100644
--- a/Modules/_io/clinic/winconsoleio.c.h
+++ b/Modules/_io/clinic/winconsoleio.c.h
@@ -428,6 +428,92 @@ _io__WindowsConsoleIO_isatty(PyObject *self, PyObject 
*Py_UNUSED(ignored))
 
 #endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
 
+#if defined(HAVE_WINDOWS_CONSOLE_IO)
+
+PyDoc_STRVAR(_io__WindowsConsoleIO_closed__doc__,
+"True if the file is closed.");
+#if defined(_IO__WINDOWSCONSOLEIO_CLOSED_DOCSTR)
+#   undef _IO__WINDOWSCONSOLEIO_CLOSED_DOCSTR
+#endif
+#define _IO__WINDOWSCONSOLEIO_CLOSED_DOCSTR _io__WindowsConsoleIO_closed__doc__
+
+#define _IO__WINDOWSCONSOLEIO_CLOSED_GETTER _io__WindowsConsoleIO_closed_get
+
+static int
+_io__WindowsConsoleIO_closed_get_impl(winconsoleio *self);
+
+static PyObject *
+_io__WindowsConsoleIO_closed_get(PyObject *self, void *Py_UNUSED(context))
+{
+    PyObject *return_value = NULL;
+    int _return_value;
+
+    _return_value = _io__WindowsConsoleIO_closed_get_impl((winconsoleio 
*)self);
+    if ((_return_value == -1) && PyErr_Occurred()) {
+        goto exit;
+    }
+    return_value = PyBool_FromLong((long)_return_value);
+
+exit:
+    return return_value;
+}
+
+#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
+
+#if defined(HAVE_WINDOWS_CONSOLE_IO)
+
+PyDoc_STRVAR(_io__WindowsConsoleIO_closefd__doc__,
+"True if the file descriptor will be closed by close().");
+#if defined(_IO__WINDOWSCONSOLEIO_CLOSEFD_DOCSTR)
+#   undef _IO__WINDOWSCONSOLEIO_CLOSEFD_DOCSTR
+#endif
+#define _IO__WINDOWSCONSOLEIO_CLOSEFD_DOCSTR 
_io__WindowsConsoleIO_closefd__doc__
+
+#define _IO__WINDOWSCONSOLEIO_CLOSEFD_GETTER _io__WindowsConsoleIO_closefd_get
+
+static int
+_io__WindowsConsoleIO_closefd_get_impl(winconsoleio *self);
+
+static PyObject *
+_io__WindowsConsoleIO_closefd_get(PyObject *self, void *Py_UNUSED(context))
+{
+    PyObject *return_value = NULL;
+    int _return_value;
+
+    _return_value = _io__WindowsConsoleIO_closefd_get_impl((winconsoleio 
*)self);
+    if ((_return_value == -1) && PyErr_Occurred()) {
+        goto exit;
+    }
+    return_value = PyBool_FromLong((long)_return_value);
+
+exit:
+    return return_value;
+}
+
+#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
+
+#if defined(HAVE_WINDOWS_CONSOLE_IO)
+
+PyDoc_STRVAR(_io__WindowsConsoleIO_mode__doc__,
+"String giving the file mode.");
+#if defined(_IO__WINDOWSCONSOLEIO_MODE_DOCSTR)
+#   undef _IO__WINDOWSCONSOLEIO_MODE_DOCSTR
+#endif
+#define _IO__WINDOWSCONSOLEIO_MODE_DOCSTR _io__WindowsConsoleIO_mode__doc__
+
+#define _IO__WINDOWSCONSOLEIO_MODE_GETTER _io__WindowsConsoleIO_mode_get
+
+static PyObject *
+_io__WindowsConsoleIO_mode_get_impl(winconsoleio *self);
+
+static PyObject *
+_io__WindowsConsoleIO_mode_get(PyObject *self, void *Py_UNUSED(context))
+{
+    return _io__WindowsConsoleIO_mode_get_impl((winconsoleio *)self);
+}
+
+#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
+
 #ifndef _IO__WINDOWSCONSOLEIO_CLOSE_METHODDEF
     #define _IO__WINDOWSCONSOLEIO_CLOSE_METHODDEF
 #endif /* !defined(_IO__WINDOWSCONSOLEIO_CLOSE_METHODDEF) */
@@ -463,4 +549,49 @@ _io__WindowsConsoleIO_isatty(PyObject *self, PyObject 
*Py_UNUSED(ignored))
 #ifndef _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF
     #define _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF
 #endif /* !defined(_IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF) */
-/*[clinic end generated code: output=dfe49dd71f4f4b1d input=a9049054013a1b77]*/
+#if defined(_IO__WINDOWSCONSOLEIO_CLOSED_GETTER) || 
defined(_IO__WINDOWSCONSOLEIO_CLOSED_SETTER)
+#  if !defined(_IO__WINDOWSCONSOLEIO_CLOSED_GETTER)
+#    define _IO__WINDOWSCONSOLEIO_CLOSED_GETTER NULL
+#  endif
+#  if !defined(_IO__WINDOWSCONSOLEIO_CLOSED_SETTER)
+#    define _IO__WINDOWSCONSOLEIO_CLOSED_SETTER NULL
+#  endif
+#  if !defined(_IO__WINDOWSCONSOLEIO_CLOSED_DOCSTR)
+#    define _IO__WINDOWSCONSOLEIO_CLOSED_DOCSTR NULL
+#  endif
+#  define _IO__WINDOWSCONSOLEIO_CLOSED_GETSETDEF {"closed", 
(getter)_IO__WINDOWSCONSOLEIO_CLOSED_GETTER, 
(setter)_IO__WINDOWSCONSOLEIO_CLOSED_SETTER, 
_IO__WINDOWSCONSOLEIO_CLOSED_DOCSTR},
+#else
+#  define _IO__WINDOWSCONSOLEIO_CLOSED_GETSETDEF
+#endif
+
+#if defined(_IO__WINDOWSCONSOLEIO_CLOSEFD_GETTER) || 
defined(_IO__WINDOWSCONSOLEIO_CLOSEFD_SETTER)
+#  if !defined(_IO__WINDOWSCONSOLEIO_CLOSEFD_GETTER)
+#    define _IO__WINDOWSCONSOLEIO_CLOSEFD_GETTER NULL
+#  endif
+#  if !defined(_IO__WINDOWSCONSOLEIO_CLOSEFD_SETTER)
+#    define _IO__WINDOWSCONSOLEIO_CLOSEFD_SETTER NULL
+#  endif
+#  if !defined(_IO__WINDOWSCONSOLEIO_CLOSEFD_DOCSTR)
+#    define _IO__WINDOWSCONSOLEIO_CLOSEFD_DOCSTR NULL
+#  endif
+#  define _IO__WINDOWSCONSOLEIO_CLOSEFD_GETSETDEF {"closefd", 
(getter)_IO__WINDOWSCONSOLEIO_CLOSEFD_GETTER, 
(setter)_IO__WINDOWSCONSOLEIO_CLOSEFD_SETTER, 
_IO__WINDOWSCONSOLEIO_CLOSEFD_DOCSTR},
+#else
+#  define _IO__WINDOWSCONSOLEIO_CLOSEFD_GETSETDEF
+#endif
+
+#if defined(_IO__WINDOWSCONSOLEIO_MODE_GETTER) || 
defined(_IO__WINDOWSCONSOLEIO_MODE_SETTER)
+#  if !defined(_IO__WINDOWSCONSOLEIO_MODE_GETTER)
+#    define _IO__WINDOWSCONSOLEIO_MODE_GETTER NULL
+#  endif
+#  if !defined(_IO__WINDOWSCONSOLEIO_MODE_SETTER)
+#    define _IO__WINDOWSCONSOLEIO_MODE_SETTER NULL
+#  endif
+#  if !defined(_IO__WINDOWSCONSOLEIO_MODE_DOCSTR)
+#    define _IO__WINDOWSCONSOLEIO_MODE_DOCSTR NULL
+#  endif
+#  define _IO__WINDOWSCONSOLEIO_MODE_GETSETDEF {"mode", 
(getter)_IO__WINDOWSCONSOLEIO_MODE_GETTER, 
(setter)_IO__WINDOWSCONSOLEIO_MODE_SETTER, _IO__WINDOWSCONSOLEIO_MODE_DOCSTR},
+#else
+#  define _IO__WINDOWSCONSOLEIO_MODE_GETSETDEF
+#endif
+
+/*[clinic end generated code: output=24fe425795203cee input=a9049054013a1b77]*/
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index e8e9c132dd3465e..e5cd7aca5de2f17 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -99,10 +99,17 @@ _PyFileIO_closed(PyObject *self)
 /* Because this can call arbitrary code, it shouldn't be called when
    the refcount is 0 (that is, not directly from tp_dealloc unless
    the refcount has been temporarily re-incremented). */
+/*[clinic input]
+_io.FileIO._dealloc_warn
+
+    source: object
+    /
+[clinic start generated code]*/
+
 static PyObject *
-fileio_dealloc_warn(PyObject *op, PyObject *source)
+_io_FileIO__dealloc_warn_impl(fileio *self, PyObject *source)
+/*[clinic end generated code: output=c7b7d122decd6575 input=3ea7e1cc0685edc2]*/
 {
-    fileio *self = PyFileIO_CAST(op);
     if (self->fd >= 0 && self->closefd) {
         PyObject *exc = PyErr_GetRaisedException();
         if (PyErr_ResourceWarning(source, 1, "unclosed file %R", source)) {
@@ -176,7 +183,7 @@ _io_FileIO_close_impl(fileio *self, PyTypeObject *cls)
         exc = PyErr_GetRaisedException();
     }
     if (self->finalizing) {
-        PyObject *r = fileio_dealloc_warn((PyObject*)self, (PyObject *) self);
+        PyObject *r = _io_FileIO__dealloc_warn_impl(self, (PyObject *)self);
         if (r) {
             Py_DECREF(r);
         }
@@ -1250,10 +1257,14 @@ _io_FileIO_isatty_impl(fileio *self)
    information. Use the stat result to skip a system call. Outside of that
    context TOCTOU issues (the fd could be arbitrarily modified by
    surrounding code). */
+/*[clinic input]
+_io.FileIO._isatty_open_only
+[clinic start generated code]*/
+
 static PyObject *
-_io_FileIO_isatty_open_only(PyObject *op, PyObject *Py_UNUSED(dummy))
+_io_FileIO__isatty_open_only_impl(fileio *self)
+/*[clinic end generated code: output=2b4689154d4b8b84 input=228767ff567cdfb6]*/
 {
-    fileio *self = PyFileIO_CAST(op);
     if (self->stat_atopen != NULL && !S_ISCHR(self->stat_atopen->st_mode)) {
         Py_RETURN_FALSE;
     }
@@ -1276,53 +1287,80 @@ static PyMethodDef fileio_methods[] = {
     _IO_FILEIO_WRITABLE_METHODDEF
     _IO_FILEIO_FILENO_METHODDEF
     _IO_FILEIO_ISATTY_METHODDEF
-    {"_isatty_open_only", _io_FileIO_isatty_open_only, METH_NOARGS},
-    {"_dealloc_warn", fileio_dealloc_warn, METH_O, NULL},
+    _IO_FILEIO__ISATTY_OPEN_ONLY_METHODDEF
+    _IO_FILEIO__DEALLOC_WARN_METHODDEF
     {"__getstate__", _PyIOBase_cannot_pickle, METH_NOARGS},
     {NULL,           NULL}             /* sentinel */
 };
 
 /* 'closed' and 'mode' are attributes for backwards compatibility reasons. */
 
-static PyObject *
-fileio_get_closed(PyObject *op, void *closure)
+/*[clinic input]
+@getter
+_io.FileIO.closed -> bool
+
+True if the file is closed.
+[clinic start generated code]*/
+
+static int
+_io_FileIO_closed_get_impl(fileio *self)
+/*[clinic end generated code: output=5052fd0688b475f2 input=6024cca6d484d9a2]*/
 {
-    fileio *self = PyFileIO_CAST(op);
-    return PyBool_FromLong((long)(self->fd < 0));
+    return self->fd < 0;
 }
 
-static PyObject *
-fileio_get_closefd(PyObject *op, void *closure)
+/*[clinic input]
+@getter
+_io.FileIO.closefd -> bool
+
+True if the file descriptor will be closed by close().
+[clinic start generated code]*/
+
+static int
+_io_FileIO_closefd_get_impl(fileio *self)
+/*[clinic end generated code: output=11963fca763399cc input=ed3d108a6f07ad5c]*/
 {
-    fileio *self = PyFileIO_CAST(op);
-    return PyBool_FromLong((long)(self->closefd));
+    return self->closefd;
 }
 
+/*[clinic input]
+@getter
+_io.FileIO.mode
+
+String giving the file mode.
+[clinic start generated code]*/
+
 static PyObject *
-fileio_get_mode(PyObject *op, void *closure)
+_io_FileIO_mode_get_impl(fileio *self)
+/*[clinic end generated code: output=d5178215493e2e7e input=300a448fc9b2fea4]*/
 {
-    fileio *self = PyFileIO_CAST(op);
     return PyUnicode_FromString(mode_string(self));
 }
 
-static PyObject *
-fileio_get_blksize(PyObject *op, void *closure)
+/*[clinic input]
+@getter
+_io.FileIO._blksize -> long
+
+Stat st_blksize if available.
+[clinic start generated code]*/
+
+static long
+_io_FileIO__blksize_get_impl(fileio *self)
+/*[clinic end generated code: output=e47eaf8cd6c0079f input=699d87d750798ccb]*/
 {
 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
-    fileio *self = PyFileIO_CAST(op);
     if (self->stat_atopen != NULL && self->stat_atopen->st_blksize > 1) {
-        return PyLong_FromLong(self->stat_atopen->st_blksize);
+        return self->stat_atopen->st_blksize;
     }
 #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
-    return PyLong_FromLong(DEFAULT_BUFFER_SIZE);
+    return DEFAULT_BUFFER_SIZE;
 }
 
 static PyGetSetDef fileio_getsetlist[] = {
-    {"closed", fileio_get_closed, NULL, "True if the file is closed"},
-    {"closefd", fileio_get_closefd, NULL,
-        "True if the file descriptor will be closed by close()."},
-    {"mode", fileio_get_mode, NULL, "String giving the file mode"},
-    {"_blksize", fileio_get_blksize, NULL, "Stat st_blksize if available"},
+    _IO_FILEIO_CLOSED_GETSETDEF
+    _IO_FILEIO_CLOSEFD_GETSETDEF
+    _IO_FILEIO_MODE_GETSETDEF
+    _IO_FILEIO__BLKSIZE_GETSETDEF
     {NULL},
 };
 
diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c
index b6d10c8568feb68..5b9b9c856431b07 100644
--- a/Modules/_io/iobase.c
+++ b/Modules/_io/iobase.c
@@ -184,14 +184,18 @@ _io__IOBase_flush_impl(PyObject *self)
     return NULL;
 }
 
-static PyObject *
-iobase_closed_get(PyObject *self, void *context)
+/*[clinic input]
+@getter
+_io._IOBase.closed -> bool
+
+True if the file is closed.
+[clinic start generated code]*/
+
+static int
+_io__IOBase_closed_get_impl(PyObject *self)
+/*[clinic end generated code: output=561af4ea236d16d9 input=e730fe4ccc4c096c]*/
 {
-    int closed = iobase_is_closed(self);
-    if (closed < 0) {
-        return NULL;
-    }
-    return PyBool_FromLong(closed);
+    return iobase_is_closed(self);
 }
 
 static int
@@ -225,25 +229,51 @@ _PyIOBase_check_closed(PyObject *self, PyObject *args)
     Py_RETURN_NONE;
 }
 
+/*[clinic input]
+_io._IOBase._checkClosed
+[clinic start generated code]*/
+
+static PyObject *
+_io__IOBase__checkClosed_impl(PyObject *self)
+/*[clinic end generated code: output=8fb8412185623f1a input=8d18d2e67b2270bb]*/
+{
+    return _PyIOBase_check_closed(self, NULL);
+}
+
+/*[clinic input]
+_io._IOBase._checkSeekable
+[clinic start generated code]*/
+
 static PyObject *
-iobase_check_seekable(PyObject *self, PyObject *args)
+_io__IOBase__checkSeekable_impl(PyObject *self)
+/*[clinic end generated code: output=10f09b515a9f4c4f input=479853eded776b0e]*/
 {
     _PyIO_State *state = find_io_state_by_def(Py_TYPE(self));
-    return _PyIOBase_check_seekable(state, self, args);
+    return _PyIOBase_check_seekable(state, self, NULL);
 }
 
+/*[clinic input]
+_io._IOBase._checkReadable
+[clinic start generated code]*/
+
 static PyObject *
-iobase_check_readable(PyObject *self, PyObject *args)
+_io__IOBase__checkReadable_impl(PyObject *self)
+/*[clinic end generated code: output=33ccab8a7c4550fb input=63fbf50b36772323]*/
 {
     _PyIO_State *state = find_io_state_by_def(Py_TYPE(self));
-    return _PyIOBase_check_readable(state, self, args);
+    return _PyIOBase_check_readable(state, self, NULL);
 }
 
+/*[clinic input]
+_io._IOBase._checkWritable
+[clinic start generated code]*/
+
 static PyObject *
-iobase_check_writable(PyObject *self, PyObject *args)
+_io__IOBase__checkWritable_impl(PyObject *self)
+/*[clinic end generated code: output=8cfc6b4b2469d2a3 input=2758c7291cf5911e]*/
 {
     _PyIO_State *state = find_io_state_by_def(Py_TYPE(self));
-    return _PyIOBase_check_writable(state, self, args);
+    return _PyIOBase_check_writable(state, self, NULL);
 }
 
 PyObject *
@@ -495,8 +525,15 @@ _PyIOBase_check_writable(_PyIO_State *state, PyObject 
*self, PyObject *args)
 
 /* Context manager */
 
+/*[clinic input]
+_io._IOBase.__enter__
+
+Context management protocol.  Returns the stream itself.
+[clinic start generated code]*/
+
 static PyObject *
-iobase_enter(PyObject *self, PyObject *args)
+_io__IOBase___enter___impl(PyObject *self)
+/*[clinic end generated code: output=d1e8e5b58bde3680 input=92e2d5e34ee714e5]*/
 {
     if (iobase_check_closed(self))
         return NULL;
@@ -504,8 +541,16 @@ iobase_enter(PyObject *self, PyObject *args)
     return Py_NewRef(self);
 }
 
+/*[clinic input]
+_io._IOBase.__exit__
+    *args: tuple
+
+Context management protocol.  Calls close().
+[clinic start generated code]*/
+
 static PyObject *
-iobase_exit(PyObject *self, PyObject *args)
+_io__IOBase___exit___impl(PyObject *self, PyObject *args)
+/*[clinic end generated code: output=452f3e33a34e2c5c input=fd3f46a32773a170]*/
 {
     return PyObject_CallMethodNoArgs(self, &_Py_ID(close));
 }
@@ -837,16 +882,16 @@ static PyMethodDef iobase_methods[] = {
     _IO__IOBASE_READABLE_METHODDEF
     _IO__IOBASE_WRITABLE_METHODDEF
 
-    {"_checkClosed",   _PyIOBase_check_closed, METH_NOARGS},
-    {"_checkSeekable", iobase_check_seekable, METH_NOARGS},
-    {"_checkReadable", iobase_check_readable, METH_NOARGS},
-    {"_checkWritable", iobase_check_writable, METH_NOARGS},
+    _IO__IOBASE__CHECKCLOSED_METHODDEF
+    _IO__IOBASE__CHECKSEEKABLE_METHODDEF
+    _IO__IOBASE__CHECKREADABLE_METHODDEF
+    _IO__IOBASE__CHECKWRITABLE_METHODDEF
 
     _IO__IOBASE_FILENO_METHODDEF
     _IO__IOBASE_ISATTY_METHODDEF
 
-    {"__enter__", iobase_enter, METH_NOARGS},
-    {"__exit__", iobase_exit, METH_VARARGS},
+    _IO__IOBASE___ENTER___METHODDEF
+    _IO__IOBASE___EXIT___METHODDEF
 
     _IO__IOBASE_READLINE_METHODDEF
     _IO__IOBASE_READLINES_METHODDEF
@@ -857,7 +902,7 @@ static PyMethodDef iobase_methods[] = {
 
 static PyGetSetDef iobase_getset[] = {
     {"__dict__", PyObject_GenericGetDict, NULL, NULL},
-    {"closed", iobase_closed_get, NULL, NULL},
+    _IO__IOBASE_CLOSED_GETSETDEF
     {NULL}
 };
 
@@ -1014,15 +1059,29 @@ _io__RawIOBase_readall_impl(PyObject *self)
     return PyBytesWriter_Finish(writer);
 }
 
+/*[clinic input]
+_io._RawIOBase.readinto
+    buffer: object
+    /
+[clinic start generated code]*/
+
 static PyObject *
-rawiobase_readinto(PyObject *self, PyObject *args)
+_io__RawIOBase_readinto(PyObject *self, PyObject *buffer)
+/*[clinic end generated code: output=081b8cdfaf3a40ff input=99d4bea2acd659c8]*/
 {
     PyErr_SetNone(PyExc_NotImplementedError);
     return NULL;
 }
 
+/*[clinic input]
+_io._RawIOBase.write
+    buffer: object
+    /
+[clinic start generated code]*/
+
 static PyObject *
-rawiobase_write(PyObject *self, PyObject *args)
+_io__RawIOBase_write(PyObject *self, PyObject *buffer)
+/*[clinic end generated code: output=7add3f2c8715c3a8 input=e6a1534adb876fe2]*/
 {
     PyErr_SetNone(PyExc_NotImplementedError);
     return NULL;
@@ -1031,8 +1090,8 @@ rawiobase_write(PyObject *self, PyObject *args)
 static PyMethodDef rawiobase_methods[] = {
     _IO__RAWIOBASE_READ_METHODDEF
     _IO__RAWIOBASE_READALL_METHODDEF
-    {"readinto", rawiobase_readinto, METH_VARARGS},
-    {"write", rawiobase_write, METH_VARARGS},
+    _IO__RAWIOBASE_READINTO_METHODDEF
+    _IO__RAWIOBASE_WRITE_METHODDEF
     {NULL, NULL}
 };
 
diff --git a/Modules/_io/stringio.c b/Modules/_io/stringio.c
index 27605b4c44239e9..93a82bcc0c6e3e9 100644
--- a/Modules/_io/stringio.c
+++ b/Modules/_io/stringio.c
@@ -68,6 +68,20 @@ static int _io_StringIO___init__(PyObject *self, PyObject 
*args, PyObject *kwarg
         return NULL; \
     }
 
+#define CHECK_INITIALIZED_INT(self) \
+    if (self->ok <= 0) { \
+        PyErr_SetString(PyExc_ValueError, \
+            "I/O operation on uninitialized object"); \
+        return -1; \
+    }
+
+#define CHECK_CLOSED_INT(self) \
+    if (self->closed) { \
+        PyErr_SetString(PyExc_ValueError, \
+            "I/O operation on closed file"); \
+        return -1; \
+    }
+
 #define ENSURE_REALIZED(self) \
     if (realize(self) < 0) { \
         return NULL; \
@@ -1013,30 +1027,30 @@ _io_StringIO___setstate___impl(stringio *self, PyObject 
*state)
 /*[clinic input]
 @critical_section
 @getter
-_io.StringIO.closed
+_io.StringIO.closed -> bool
 [clinic start generated code]*/
 
-static PyObject *
+static int
 _io_StringIO_closed_get_impl(stringio *self)
-/*[clinic end generated code: output=531ddca7954331d6 input=178d2ef24395fd49]*/
+/*[clinic end generated code: output=754068c44422cafa input=ea05e89b945e721c]*/
 {
-    CHECK_INITIALIZED(self);
-    return PyBool_FromLong(self->closed);
+    CHECK_INITIALIZED_INT(self);
+    return self->closed;
 }
 
 /*[clinic input]
 @critical_section
 @getter
-_io.StringIO.line_buffering
+_io.StringIO.line_buffering -> bool
 [clinic start generated code]*/
 
-static PyObject *
+static int
 _io_StringIO_line_buffering_get_impl(stringio *self)
-/*[clinic end generated code: output=360710e0112966ae input=6a7634e7f890745e]*/
+/*[clinic end generated code: output=56c0edde9001fb37 input=326f8b3bd1feb699]*/
 {
-    CHECK_INITIALIZED(self);
-    CHECK_CLOSED(self);
-    Py_RETURN_FALSE;
+    CHECK_INITIALIZED_INT(self);
+    CHECK_CLOSED_INT(self);
+    return 0;
 }
 
 /*[clinic input]
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index a744a885932cdf5..8f98f7d80095b0b 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -635,10 +635,15 @@ _io_IncrementalNewlineDecoder_reset_impl(nldecoder_object 
*self)
         Py_RETURN_NONE;
 }
 
+/*[clinic input]
+@getter
+_io.IncrementalNewlineDecoder.newlines
+[clinic start generated code]*/
+
 static PyObject *
-incrementalnewlinedecoder_newlines_get(PyObject *op, void *Py_UNUSED(context))
+_io_IncrementalNewlineDecoder_newlines_get_impl(nldecoder_object *self)
+/*[clinic end generated code: output=4370cf5202a83d08 input=040f9a26aef317a8]*/
 {
-    nldecoder_object *self = nldecoder_object_CAST(op);
     CHECK_INITIALIZED_DECODER(self);
 
     switch (self->seennl) {
@@ -3394,38 +3399,35 @@ _io_TextIOWrapper_errors_get_impl(textio *self)
 /*[clinic input]
 @critical_section
 @getter
-_io.TextIOWrapper._CHUNK_SIZE
+_io.TextIOWrapper._CHUNK_SIZE -> Py_ssize_t
 [clinic start generated code]*/
 
-static PyObject *
+static Py_ssize_t
 _io_TextIOWrapper__CHUNK_SIZE_get_impl(textio *self)
-/*[clinic end generated code: output=039925cd2df375bc input=e9715b0e06ff0fa6]*/
+/*[clinic end generated code: output=3fe34b873b6b2c8c input=cae767b74b6b46bd]*/
 {
-    CHECK_ATTACHED(self);
-    return PyLong_FromSsize_t(self->chunk_size);
+    CHECK_ATTACHED_INT(self);
+    return self->chunk_size;
 }
 
 /*[clinic input]
 @critical_section
 @setter
 _io.TextIOWrapper._CHUNK_SIZE
+    value: Py_ssize_t
 [clinic start generated code]*/
 
 static int
-_io_TextIOWrapper__CHUNK_SIZE_set_impl(textio *self, PyObject *value)
-/*[clinic end generated code: output=edb86d2db660a5ab input=32fc99861db02a0a]*/
+_io_TextIOWrapper__CHUNK_SIZE_set_impl(textio *self, Py_ssize_t value)
+/*[clinic end generated code: output=5170a93dd4d74917 input=ede7bae6145f941b]*/
 {
-    Py_ssize_t n;
     CHECK_ATTACHED_INT(self);
-    n = PyNumber_AsSsize_t(value, PyExc_ValueError);
-    if (n == -1 && PyErr_Occurred())
-        return -1;
-    if (n <= 0) {
+    if (value <= 0) {
         PyErr_SetString(PyExc_ValueError,
                         "a strictly positive integer is required");
         return -1;
     }
-    self->chunk_size = n;
+    self->chunk_size = value;
     return 0;
 }
 
@@ -3451,7 +3453,7 @@ static PyMethodDef incrementalnewlinedecoder_methods[] = {
 };
 
 static PyGetSetDef incrementalnewlinedecoder_getset[] = {
-    {"newlines", incrementalnewlinedecoder_newlines_get, NULL, NULL},
+    _IO_INCREMENTALNEWLINEDECODER_NEWLINES_GETSETDEF
     {NULL}
 };
 
diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c
index 11e29227d9276e9..e3e57d8df455530 100644
--- a/Modules/_io/winconsoleio.c
+++ b/Modules/_io/winconsoleio.c
@@ -1202,32 +1202,52 @@ static PyMethodDef winconsoleio_methods[] = {
 
 /* 'closed' and 'mode' are attributes for compatibility with FileIO. */
 
-static PyObject *
-get_closed(PyObject *op, void *Py_UNUSED(closure))
+/*[clinic input]
+@getter
+_io._WindowsConsoleIO.closed -> bool
+
+True if the file is closed.
+[clinic start generated code]*/
+
+static int
+_io__WindowsConsoleIO_closed_get_impl(winconsoleio *self)
+/*[clinic end generated code: output=a3f8b93c6ddcf660 input=65b6d1bed0aadbb8]*/
 {
-    winconsoleio *self = winconsoleio_CAST(op);
-    return PyBool_FromLong((long)(self->fd == -1));
+    return self->fd == -1;
 }
 
-static PyObject *
-get_closefd(PyObject *op, void *Py_UNUSED(closure))
+/*[clinic input]
+@getter
+_io._WindowsConsoleIO.closefd -> bool
+
+True if the file descriptor will be closed by close().
+[clinic start generated code]*/
+
+static int
+_io__WindowsConsoleIO_closefd_get_impl(winconsoleio *self)
+/*[clinic end generated code: output=ec221c2f949530a3 input=5839d3a815edecee]*/
 {
-    winconsoleio *self = winconsoleio_CAST(op);
-    return PyBool_FromLong((long)(self->closefd));
+    return self->closefd;
 }
 
+/*[clinic input]
+@getter
+_io._WindowsConsoleIO.mode
+
+String giving the file mode.
+[clinic start generated code]*/
+
 static PyObject *
-get_mode(PyObject *op, void *Py_UNUSED(closure))
+_io__WindowsConsoleIO_mode_get_impl(winconsoleio *self)
+/*[clinic end generated code: output=2d7c4cabf96e5281 input=e1fa9cd881117c0f]*/
 {
-    winconsoleio *self = winconsoleio_CAST(op);
     return PyUnicode_FromString(self->readable ? "rb" : "wb");
 }
 
 static PyGetSetDef winconsoleio_getsetlist[] = {
-    {"closed", get_closed, NULL, "True if the file is closed"},
-    {"closefd", get_closefd, NULL,
-        "True if the file descriptor will be closed by close()."},
-    {"mode", get_mode, NULL, "String giving the file mode"},
+    _IO__WINDOWSCONSOLEIO_CLOSED_GETSETDEF
+    _IO__WINDOWSCONSOLEIO_CLOSEFD_GETSETDEF
+    _IO__WINDOWSCONSOLEIO_MODE_GETSETDEF
     {NULL},
 };
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to