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

Skip to content

Commit af62c7d

Browse files
author
Victor Stinner
committed
(Merge 3.2) Issue #12175: FileIO.readall() now raises a ValueError instead of
an IOError if the file is closed.
2 parents fd82113 + 4767114 commit af62c7d

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
@@ -2512,6 +2512,8 @@ def test_io_after_close(self):
25122512
self.assertRaises(ValueError, f.read)
25132513
if hasattr(f, "read1"):
25142514
self.assertRaises(ValueError, f.read1, 1024)
2515+
if hasattr(f, "readall"):
2516+
self.assertRaises(ValueError, f.readall)
25152517
if hasattr(f, "readinto"):
25162518
self.assertRaises(ValueError, f.readinto, bytearray(1024))
25172519
self.assertRaises(ValueError, f.readline)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,9 @@ Core and Builtins
10621062
Library
10631063
-------
10641064

1065+
- Issue #12175: FileIO.readall() now raises a ValueError instead of an IOError
1066+
if the file is closed.
1067+
10651068
- Issue #10916: mmap should not segfault when a file is mapped using 0 as length
10661069
and a non-zero offset, and an attempt to read past the end of file is made
10671070
(IndexError is raised instead). Patch by Ross Lagerwall.

Modules/_io/fileio.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,8 @@ fileio_readall(fileio *self)
583583
Py_ssize_t total = 0;
584584
int n;
585585

586+
if (self->fd < 0)
587+
return err_closed();
586588
if (!_PyVerify_fd(self->fd))
587589
return PyErr_SetFromErrno(PyExc_IOError);
588590

0 commit comments

Comments
 (0)