bpo-34068: _io__IOBase_close_impl could call _PyObject_SetAttrId with an exception set (GH-8282)
(cherry picked from commit 28f07364f066792ceee93231dbb80ae8ad98b2bb)
Co-authored-by: Zackery Spytz <zspytz@gmail.com>
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index a03a7f7..c68b2fe 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -968,6 +968,16 @@
self.assertSequenceEqual(buffer[result:], unused)
self.assertEqual(len(reader.avail), avail - result)
+ def test_close_assert(self):
+ class R(self.IOBase):
+ def __setattr__(self, name, value):
+ pass
+ def flush(self):
+ raise OSError()
+ f = R()
+ # This would cause an assertion failure.
+ self.assertRaises(OSError, f.close)
+
class CIOTest(IOTest):