https://github.com/python/cpython/commit/8dbc313ff9e36d38062532646c6c7faeab560115
commit: 8dbc313ff9e36d38062532646c6c7faeab560115
branch: main
author: Stan Ulbrych <[email protected]>
committer: StanFromIreland <[email protected]>
date: 2026-10-29T16:58:18Z
summary:

gh-160781: Only test BytesIO write overflow on the C implementation (#160903)

files:
M Lib/test/test_io/test_memoryio.py

diff --git a/Lib/test/test_io/test_memoryio.py 
b/Lib/test/test_io/test_memoryio.py
index 48337ae9e80a53..e8b47951b403c1 100644
--- a/Lib/test/test_io/test_memoryio.py
+++ b/Lib/test/test_io/test_memoryio.py
@@ -591,10 +591,6 @@ def test_issue141311(self):
         self.assertEqual(sys.maxsize, memio.seek(sys.maxsize))
         buf = bytearray(2)
         self.assertEqual(0, memio.readinto(buf))
-        # Writing there must not overflow the buffer size.
-        memio.seek(sys.maxsize - 1)
-        self.assertRaises((MemoryError, OverflowError), memio.write, b"x")
-        self.assertEqual(memio.getvalue(), b"")
 
     def test_peek(self):
         buf = self.buftype("1234567890")
@@ -994,6 +990,15 @@ def __index__(self):
             self.assertEqual(stream.truncate(2**31), 2**31)
             self.assertEqual(stream.getvalue(), b'abc')
 
+    def test_write_overflow(self):
+        # gh-160781: overallocation at a position near sys.maxsize
+        # must raise OverflowError, not SystemError.
+        memio = self.ioclass()
+        memio.seek(sys.maxsize - 1)
+        self.assertRaises(OverflowError, memio.write, b"x")
+        self.assertEqual(memio.getvalue(), b"")
+        self.assertEqual(memio.tell(), sys.maxsize - 1)
+
     def test_readinto_overlapping_buffer(self):
         with self.ioclass(b'abcd') as stream:
             with stream.getbuffer()[1:] as target:

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to