Skip to content

Commit 886a4d7

Browse files
authored
gh-129011: Update comments in FileIO to match current code (#129012)
1 parent a385add commit 886a4d7

File tree

3 files changed

+43
-16
lines changed

3 files changed

+43
-16
lines changed

Lib/_pyio.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,13 @@ def _checkWritable(self, msg=None):
16451645
def read(self, size=None):
16461646
"""Read at most size bytes, returned as bytes.
16471647
1648-
Only makes one system call, so less data may be returned than requested
1648+
If size is less than 0, read all bytes in the file making
1649+
multiple read calls. See ``FileIO.readall``.
1650+
1651+
Attempts to make only one system call, retrying only per
1652+
PEP 475 (EINTR). This means less data may be returned than
1653+
requested.
1654+
16491655
In non-blocking mode, returns None if no data is available.
16501656
Return an empty bytes object at EOF.
16511657
"""
@@ -1661,8 +1667,13 @@ def read(self, size=None):
16611667
def readall(self):
16621668
"""Read all data from the file, returned as bytes.
16631669
1664-
In non-blocking mode, returns as much as is immediately available,
1665-
or None if no data is available. Return an empty bytes object at EOF.
1670+
Reads until either there is an error or read() returns size 0
1671+
(indicates EOF). If the file is already at EOF, returns an
1672+
empty bytes object.
1673+
1674+
In non-blocking mode, returns as much data as could be read
1675+
before EAGAIN. If no data is available (EAGAIN is returned
1676+
before bytes are read) returns None.
16661677
"""
16671678
self._checkClosed()
16681679
self._checkReadable()

Modules/_io/clinic/fileio.c.h

Lines changed: 14 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_io/fileio.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -727,13 +727,16 @@ _io.FileIO.readall
727727
728728
Read all data from the file, returned as bytes.
729729
730-
In non-blocking mode, returns as much as is immediately available,
731-
or None if no data is available. Return an empty bytes object at EOF.
730+
Reads until either there is an error or read() returns size 0 (indicates EOF).
731+
If the file is already at EOF, returns an empty bytes object.
732+
733+
In non-blocking mode, returns as much data as could be read before EAGAIN. If no
734+
data is available (EAGAIN is returned before bytes are read) returns None.
732735
[clinic start generated code]*/
733736

734737
static PyObject *
735738
_io_FileIO_readall_impl(fileio *self)
736-
/*[clinic end generated code: output=faa0292b213b4022 input=dbdc137f55602834]*/
739+
/*[clinic end generated code: output=faa0292b213b4022 input=1e19849857f5d0a1]*/
737740
{
738741
Py_off_t pos, end;
739742
PyObject *result;
@@ -848,14 +851,19 @@ _io.FileIO.read
848851
849852
Read at most size bytes, returned as bytes.
850853
851-
Only makes one system call, so less data may be returned than requested.
852-
In non-blocking mode, returns None if no data is available.
853-
Return an empty bytes object at EOF.
854+
If size is less than 0, read all bytes in the file making multiple read calls.
855+
See ``FileIO.readall``.
856+
857+
Attempts to make only one system call, retrying only per PEP 475 (EINTR). This
858+
means less data may be returned than requested.
859+
860+
In non-blocking mode, returns None if no data is available. Return an empty
861+
bytes object at EOF.
854862
[clinic start generated code]*/
855863

856864
static PyObject *
857865
_io_FileIO_read_impl(fileio *self, PyTypeObject *cls, Py_ssize_t size)
858-
/*[clinic end generated code: output=bbd749c7c224143e input=f613d2057e4a1918]*/
866+
/*[clinic end generated code: output=bbd749c7c224143e input=cf21fddef7d38ab6]*/
859867
{
860868
char *ptr;
861869
Py_ssize_t n;

0 commit comments

Comments
 (0)