diff --git a/Lib/_pyio.py b/Lib/_pyio.py index 755e0258770891..7d96044f2ce23f 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -1702,7 +1702,7 @@ def readall(self): bytes_read += n del result[bytes_read:] - return bytes(result) + return result def readinto(self, buffer): """Same as RawIOBase.readinto().""" diff --git a/Lib/test/test_largefile.py b/Lib/test/test_largefile.py index 41f7b70e5cfe81..438a90a92ed588 100644 --- a/Lib/test/test_largefile.py +++ b/Lib/test/test_largefile.py @@ -56,9 +56,7 @@ class TestFileMethods(LargeFileTest): (i.e. > 2 GiB) files. """ - # _pyio.FileIO.readall() uses a temporary bytearray then casted to bytes, - # so memuse=2 is needed - @bigmemtest(size=size, memuse=2, dry_run=False) + @bigmemtest(size=size, memuse=1, dry_run=False) def test_large_read(self, _size): # bpo-24658: Test that a read greater than 2GB does not fail. with self.open(TESTFN, "rb") as f: @@ -154,7 +152,7 @@ def test_seekable(self): f.seek(pos) self.assertTrue(f.seekable()) - @bigmemtest(size=size, memuse=2, dry_run=False) + @bigmemtest(size=size, memuse=1, dry_run=False) def test_seek_readall(self, _size): # Seek which doesn't change position should readall successfully. with self.open(TESTFN, 'rb') as f: diff --git a/Misc/NEWS.d/next/Library/2025-01-28-21-51-50.gh-issue-129005.OIdODu.rst b/Misc/NEWS.d/next/Library/2025-01-28-21-51-50.gh-issue-129005.OIdODu.rst new file mode 100644 index 00000000000000..595b39d56dbb36 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-01-28-21-51-50.gh-issue-129005.OIdODu.rst @@ -0,0 +1,2 @@ +:mod:`!_pyio`: Return bytearray from ``_pyio.FileIO.readall()`` rather than +copying into a bytes. Memory usage now matches ``_io.FileIO.readall()``