From 59c763efc9d359ed92b4fd6bd5df7764e365d998 Mon Sep 17 00:00:00 2001 From: Cody Maloney Date: Sat, 18 Jan 2025 16:57:53 -0800 Subject: [PATCH 1/8] Update comments in FileIO to match current code --- Modules/_io/fileio.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index cf0f1d671b507a..f91febe6363cd9 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -725,8 +725,11 @@ _io.FileIO.readall Read all data from the file, returned as bytes. -In non-blocking mode, returns as much as is immediately available, -or None if no data is available. Return an empty bytes object at EOF. +Reads until either there is an error or read() returns size 0 (indicates EOF). +If the file is already at EOF returns empty bytes. + +In non-blocking mode, returns as much data as could be read before EAGAIN. If no +data is available (EAGAIN is returned before bytes are read) returns None. [clinic start generated code]*/ static PyObject * @@ -846,9 +849,14 @@ _io.FileIO.read Read at most size bytes, returned as bytes. -Only makes one system call, so less data may be returned than requested. -In non-blocking mode, returns None if no data is available. -Return an empty bytes object at EOF. +If size is less than 0, read all bytes in the file making multiple read calls. +See ``_io.FileIO.readall``. + +Attempts to make only one system call, retrying only per PEP-475 (EINTR). This +means less data may be returned than requested. + +In non-blocking mode, returns None if no data is available. Return an empty +bytes object at EOF. [clinic start generated code]*/ static PyObject * From 9b714f29195d5d5eda875853f2e26843a7b40bba Mon Sep 17 00:00:00 2001 From: Cody Maloney Date: Sat, 18 Jan 2025 18:25:27 -0800 Subject: [PATCH 2/8] Regenerate clinic --- Modules/_io/clinic/fileio.c.h | 20 ++++++++++++++------ Modules/_io/fileio.c | 4 ++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Modules/_io/clinic/fileio.c.h b/Modules/_io/clinic/fileio.c.h index 0b8b4a49ac24b6..f3bcc0f54c586a 100644 --- a/Modules/_io/clinic/fileio.c.h +++ b/Modules/_io/clinic/fileio.c.h @@ -268,8 +268,11 @@ PyDoc_STRVAR(_io_FileIO_readall__doc__, "\n" "Read all data from the file, returned as bytes.\n" "\n" -"In non-blocking mode, returns as much as is immediately available,\n" -"or None if no data is available. Return an empty bytes object at EOF."); +"Reads until either there is an error or read() returns size 0 (indicates EOF).\n" +"If the file is already at EOF returns empty bytes.\n" +"\n" +"In non-blocking mode, returns as much data as could be read before EAGAIN. If no\n" +"data is available (EAGAIN is returned before bytes are read) returns None."); #define _IO_FILEIO_READALL_METHODDEF \ {"readall", (PyCFunction)_io_FileIO_readall, METH_NOARGS, _io_FileIO_readall__doc__}, @@ -289,9 +292,14 @@ PyDoc_STRVAR(_io_FileIO_read__doc__, "\n" "Read at most size bytes, returned as bytes.\n" "\n" -"Only makes one system call, so less data may be returned than requested.\n" -"In non-blocking mode, returns None if no data is available.\n" -"Return an empty bytes object at EOF."); +"If size is less than 0, read all bytes in the file making multiple read calls.\n" +"See ``_io.FileIO.readall``.\n" +"\n" +"Attempts to make only one system call, retrying only per PEP-475 (EINTR). This\n" +"means less data may be returned than requested.\n" +"\n" +"In non-blocking mode, returns None if no data is available. Return an empty\n" +"bytes object at EOF."); #define _IO_FILEIO_READ_METHODDEF \ {"read", _PyCFunction_CAST(_io_FileIO_read), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io_FileIO_read__doc__}, @@ -533,4 +541,4 @@ _io_FileIO_isatty(fileio *self, PyObject *Py_UNUSED(ignored)) #ifndef _IO_FILEIO_TRUNCATE_METHODDEF #define _IO_FILEIO_TRUNCATE_METHODDEF #endif /* !defined(_IO_FILEIO_TRUNCATE_METHODDEF) */ -/*[clinic end generated code: output=1c262ae135da4dcb input=a9049054013a1b77]*/ +/*[clinic end generated code: output=565cc8b58b3ab225 input=a9049054013a1b77]*/ diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index f91febe6363cd9..adb3e0626253c8 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -734,7 +734,7 @@ data is available (EAGAIN is returned before bytes are read) returns None. static PyObject * _io_FileIO_readall_impl(fileio *self) -/*[clinic end generated code: output=faa0292b213b4022 input=dbdc137f55602834]*/ +/*[clinic end generated code: output=faa0292b213b4022 input=5f8c884ba8aa1a3e]*/ { Py_off_t pos, end; PyObject *result; @@ -861,7 +861,7 @@ bytes object at EOF. static PyObject * _io_FileIO_read_impl(fileio *self, PyTypeObject *cls, Py_ssize_t size) -/*[clinic end generated code: output=bbd749c7c224143e input=f613d2057e4a1918]*/ +/*[clinic end generated code: output=bbd749c7c224143e input=a508789e8d9468b4]*/ { char *ptr; Py_ssize_t n; From abe4436ca5ae2398e243b9292b6d1ded880c0a27 Mon Sep 17 00:00:00 2001 From: Cody Maloney Date: Sun, 19 Jan 2025 08:12:54 -0800 Subject: [PATCH 3/8] Update Modules/_io/fileio.c Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- Modules/_io/fileio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index adb3e0626253c8..9b88c887591577 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -726,7 +726,7 @@ _io.FileIO.readall Read all data from the file, returned as bytes. Reads until either there is an error or read() returns size 0 (indicates EOF). -If the file is already at EOF returns empty bytes. +If the file is already at EOF, returns an empty bytes object. In non-blocking mode, returns as much data as could be read before EAGAIN. If no data is available (EAGAIN is returned before bytes are read) returns None. From b0f3afecb6efab60b2c9906d913cb43299ff38e5 Mon Sep 17 00:00:00 2001 From: Cody Maloney Date: Sun, 19 Jan 2025 08:54:19 -0800 Subject: [PATCH 4/8] Regenerate clinic --- Modules/_io/clinic/fileio.c.h | 4 ++-- Modules/_io/fileio.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/_io/clinic/fileio.c.h b/Modules/_io/clinic/fileio.c.h index f3bcc0f54c586a..be7a5f34da3222 100644 --- a/Modules/_io/clinic/fileio.c.h +++ b/Modules/_io/clinic/fileio.c.h @@ -269,7 +269,7 @@ PyDoc_STRVAR(_io_FileIO_readall__doc__, "Read all data from the file, returned as bytes.\n" "\n" "Reads until either there is an error or read() returns size 0 (indicates EOF).\n" -"If the file is already at EOF returns empty bytes.\n" +"If the file is already at EOF, returns an empty bytes object.\n" "\n" "In non-blocking mode, returns as much data as could be read before EAGAIN. If no\n" "data is available (EAGAIN is returned before bytes are read) returns None."); @@ -541,4 +541,4 @@ _io_FileIO_isatty(fileio *self, PyObject *Py_UNUSED(ignored)) #ifndef _IO_FILEIO_TRUNCATE_METHODDEF #define _IO_FILEIO_TRUNCATE_METHODDEF #endif /* !defined(_IO_FILEIO_TRUNCATE_METHODDEF) */ -/*[clinic end generated code: output=565cc8b58b3ab225 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=22ae2eaea0dd44da input=a9049054013a1b77]*/ diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index 9b88c887591577..1b355d3b330a87 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -734,7 +734,7 @@ data is available (EAGAIN is returned before bytes are read) returns None. static PyObject * _io_FileIO_readall_impl(fileio *self) -/*[clinic end generated code: output=faa0292b213b4022 input=5f8c884ba8aa1a3e]*/ +/*[clinic end generated code: output=faa0292b213b4022 input=1e19849857f5d0a1]*/ { Py_off_t pos, end; PyObject *result; From 514dad31364986564819fa36e9a732b7f94e12b6 Mon Sep 17 00:00:00 2001 From: Cody Maloney Date: Sat, 1 Mar 2025 11:14:05 -0800 Subject: [PATCH 5/8] Update _pyio docs to match _io --- Lib/_pyio.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Lib/_pyio.py b/Lib/_pyio.py index 14961c39d3541d..efe3462141fc27 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -1636,7 +1636,13 @@ def _checkWritable(self, msg=None): def read(self, size=None): """Read at most size bytes, returned as bytes. - Only makes one system call, so less data may be returned than requested + If size is less than 0, read all bytes in the file making + multiple read calls. See ``_io.FileIO.readall``. + + Attempts to make only one system call, retrying only per + PEP-475 (EINTR). This means less data may be returned than + requested. + In non-blocking mode, returns None if no data is available. Return an empty bytes object at EOF. """ @@ -1652,8 +1658,13 @@ def read(self, size=None): def readall(self): """Read all data from the file, returned as bytes. - In non-blocking mode, returns as much as is immediately available, - or None if no data is available. Return an empty bytes object at EOF. + Reads until either there is an error or read() returns size 0 + (indicates EOF). If the file is already at EOF, returns an + empty bytes object. + + In non-blocking mode, returns as much data as could be read + before EAGAIN. If no data is available (EAGAIN is returned + before bytes are read) returns None. """ self._checkClosed() self._checkReadable() From 600f064344702f4c981347d990b5b96bc60853ff Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Thu, 6 Mar 2025 15:51:16 -0800 Subject: [PATCH 6/8] Apply suggestions from code review --- Lib/_pyio.py | 2 +- Modules/_io/fileio.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/_pyio.py b/Lib/_pyio.py index 40f067b499871e..1f91ae48e496c4 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -1649,7 +1649,7 @@ def read(self, size=None): multiple read calls. See ``_io.FileIO.readall``. Attempts to make only one system call, retrying only per - PEP-475 (EINTR). This means less data may be returned than + PEP 475 (EINTR). This means less data may be returned than requested. In non-blocking mode, returns None if no data is available. diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index b180882bdbea6a..05987e3f36cedb 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -854,7 +854,7 @@ Read at most size bytes, returned as bytes. If size is less than 0, read all bytes in the file making multiple read calls. See ``_io.FileIO.readall``. -Attempts to make only one system call, retrying only per PEP-475 (EINTR). This +Attempts to make only one system call, retrying only per PEP 475 (EINTR). This means less data may be returned than requested. In non-blocking mode, returns None if no data is available. Return an empty From 82d6f176b7add8206d4a730449cd860ce45c54dc Mon Sep 17 00:00:00 2001 From: Cody Maloney Date: Thu, 6 Mar 2025 16:26:38 -0800 Subject: [PATCH 7/8] make regen-clinic --- Modules/_io/clinic/fileio.c.h | 4 ++-- Modules/_io/fileio.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/_io/clinic/fileio.c.h b/Modules/_io/clinic/fileio.c.h index 6b10f9bd02c072..41decec9a3244c 100644 --- a/Modules/_io/clinic/fileio.c.h +++ b/Modules/_io/clinic/fileio.c.h @@ -295,7 +295,7 @@ PyDoc_STRVAR(_io_FileIO_read__doc__, "If size is less than 0, read all bytes in the file making multiple read calls.\n" "See ``_io.FileIO.readall``.\n" "\n" -"Attempts to make only one system call, retrying only per PEP-475 (EINTR). This\n" +"Attempts to make only one system call, retrying only per PEP 475 (EINTR). This\n" "means less data may be returned than requested.\n" "\n" "In non-blocking mode, returns None if no data is available. Return an empty\n" @@ -541,4 +541,4 @@ _io_FileIO_isatty(PyObject *self, PyObject *Py_UNUSED(ignored)) #ifndef _IO_FILEIO_TRUNCATE_METHODDEF #define _IO_FILEIO_TRUNCATE_METHODDEF #endif /* !defined(_IO_FILEIO_TRUNCATE_METHODDEF) */ -/*[clinic end generated code: output=b95380624f757366 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=02117cfbca5535d1 input=a9049054013a1b77]*/ diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index 05987e3f36cedb..bcade9f87883ba 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -863,7 +863,7 @@ bytes object at EOF. static PyObject * _io_FileIO_read_impl(fileio *self, PyTypeObject *cls, Py_ssize_t size) -/*[clinic end generated code: output=bbd749c7c224143e input=a508789e8d9468b4]*/ +/*[clinic end generated code: output=bbd749c7c224143e input=e8376d92a521d865]*/ { char *ptr; Py_ssize_t n; From 74abf3639929e226f188a9d1662ccc5c5e67bab9 Mon Sep 17 00:00:00 2001 From: Cody Maloney Date: Thu, 6 Mar 2025 16:48:51 -0800 Subject: [PATCH 8/8] Refer to FileIO not _io.FileIO, also get build to re-run --- Lib/_pyio.py | 2 +- Modules/_io/clinic/fileio.c.h | 4 ++-- Modules/_io/fileio.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Lib/_pyio.py b/Lib/_pyio.py index 1f91ae48e496c4..7e44c5aaeda669 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -1646,7 +1646,7 @@ def read(self, size=None): """Read at most size bytes, returned as bytes. If size is less than 0, read all bytes in the file making - multiple read calls. See ``_io.FileIO.readall``. + multiple read calls. See ``FileIO.readall``. Attempts to make only one system call, retrying only per PEP 475 (EINTR). This means less data may be returned than diff --git a/Modules/_io/clinic/fileio.c.h b/Modules/_io/clinic/fileio.c.h index 41decec9a3244c..bc816ea030fc80 100644 --- a/Modules/_io/clinic/fileio.c.h +++ b/Modules/_io/clinic/fileio.c.h @@ -293,7 +293,7 @@ PyDoc_STRVAR(_io_FileIO_read__doc__, "Read at most size bytes, returned as bytes.\n" "\n" "If size is less than 0, read all bytes in the file making multiple read calls.\n" -"See ``_io.FileIO.readall``.\n" +"See ``FileIO.readall``.\n" "\n" "Attempts to make only one system call, retrying only per PEP 475 (EINTR). This\n" "means less data may be returned than requested.\n" @@ -541,4 +541,4 @@ _io_FileIO_isatty(PyObject *self, PyObject *Py_UNUSED(ignored)) #ifndef _IO_FILEIO_TRUNCATE_METHODDEF #define _IO_FILEIO_TRUNCATE_METHODDEF #endif /* !defined(_IO_FILEIO_TRUNCATE_METHODDEF) */ -/*[clinic end generated code: output=02117cfbca5535d1 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=f4e1f74c03d4ecdf input=a9049054013a1b77]*/ diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index bcade9f87883ba..54e5270f8161d6 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -852,7 +852,7 @@ _io.FileIO.read Read at most size bytes, returned as bytes. If size is less than 0, read all bytes in the file making multiple read calls. -See ``_io.FileIO.readall``. +See ``FileIO.readall``. Attempts to make only one system call, retrying only per PEP 475 (EINTR). This means less data may be returned than requested. @@ -863,7 +863,7 @@ bytes object at EOF. static PyObject * _io_FileIO_read_impl(fileio *self, PyTypeObject *cls, Py_ssize_t size) -/*[clinic end generated code: output=bbd749c7c224143e input=e8376d92a521d865]*/ +/*[clinic end generated code: output=bbd749c7c224143e input=cf21fddef7d38ab6]*/ { char *ptr; Py_ssize_t n;