Skip to content

Commit 409b9a9

Browse files
committed
Fix ternary, doc method ref, move test to just c impl
1 parent dacd3c1 commit 409b9a9

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

Lib/test/test_io/test_bufferedio.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -922,14 +922,6 @@ def test_slow_close_from_thread(self):
922922
self.assertTrue(bufio.closed)
923923
t.join()
924924

925-
def test_close_without_closed(self):
926-
# gh-140650: check TypeError is raised
927-
class MockRawIOWithoutClosed(self.MockRawIO):
928-
closed = NotImplemented
929-
930-
bufio = self.tp(MockRawIOWithoutClosed())
931-
self.assertRaises(TypeError, bufio.close)
932-
933925

934926
class CBufferedWriterTest(BufferedWriterTest, SizeofTest, CTestCase):
935927
tp = io.BufferedWriter
@@ -970,6 +962,14 @@ def test_args_error(self):
970962
with self.assertRaisesRegex(TypeError, "BufferedWriter"):
971963
self.tp(self.BytesIO(), 1024, 1024, 1024)
972964

965+
def test_close_without_closed(self):
966+
# gh-140650: check TypeError is raised
967+
class MockRawIOWithoutClosed(self.MockRawIO):
968+
closed = NotImplemented
969+
970+
bufio = self.tp(MockRawIOWithoutClosed())
971+
self.assertRaises(TypeError, bufio.close)
972+
973973

974974
class PyBufferedWriterTest(BufferedWriterTest, PyTestCase):
975975
tp = pyio.BufferedWriter
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Fix an issue where :meth:`io.BufferedWriter.close` would crash when "closed"
2-
was not implemented.
1+
Fix an issue where closing :class:`io.BufferedWriter` could crash
2+
if the closed attribute had the wrong type.

Modules/_io/bufferedio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ _enter_buffered_busy(buffered *self)
362362
}
363363

364364
#define IS_CLOSED(self) \
365-
(!self->buffer ?: \
365+
(!self->buffer ? !self->buffer : \
366366
(self->fast_closed_checks \
367367
? _PyFileIO_closed(self->raw) \
368368
: buffered_closed(self)))

0 commit comments

Comments
 (0)