Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b79f28c

Browse files
author
Victor Stinner
committed
Issue #12175: FileIO.readall() now raises a ValueError instead of an IOError if
the file is closed.
1 parent 46f8264 commit b79f28c

3 files changed

Lines changed: 7 additions & 0 deletions

File tree

Lib/test/test_io.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,6 +2467,8 @@ def test_io_after_close(self):
24672467
self.assertRaises(ValueError, f.read)
24682468
if hasattr(f, "read1"):
24692469
self.assertRaises(ValueError, f.read1, 1024)
2470+
if hasattr(f, "readall"):
2471+
self.assertRaises(ValueError, f.readall)
24702472
if hasattr(f, "readinto"):
24712473
self.assertRaises(ValueError, f.readinto, bytearray(1024))
24722474
self.assertRaises(ValueError, f.readline)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ Core and Builtins
7575
Library
7676
-------
7777

78+
- Issue #12175: FileIO.readall() now raises a ValueError instead of an IOError
79+
if the file is closed.
80+
7881
- Issue #12100: Don't reset incremental encoders of CJK codecs at each call to
7982
their encode() method anymore, but continue to call the reset() method if the
8083
final argument is True.

Modules/_io/fileio.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@ fileio_readall(fileio *self)
536536
Py_ssize_t total = 0;
537537
int n;
538538

539+
if (self->fd < 0)
540+
return err_closed();
539541
if (!_PyVerify_fd(self->fd))
540542
return PyErr_SetFromErrno(PyExc_IOError);
541543

0 commit comments

Comments
 (0)