Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Lib/test/test_io/test_bufferedio.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,14 @@ def test_args_error(self):
with self.assertRaisesRegex(TypeError, "BufferedWriter"):
self.tp(self.BytesIO(), 1024, 1024, 1024)

def test_close_without_closed(self):
# gh-140650: check TypeError is raised
class MockRawIOWithoutClosed(self.MockRawIO):
closed = NotImplemented

bufio = self.tp(MockRawIOWithoutClosed())
self.assertRaises(TypeError, bufio.close)


class PyBufferedWriterTest(BufferedWriterTest, PyTestCase):
tp = pyio.BufferedWriter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix an issue where closing :class:`io.BufferedWriter` could crash
if the closed attribute had the wrong type.
2 changes: 1 addition & 1 deletion Modules/_io/bufferedio.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ _enter_buffered_busy(buffered *self)
}

#define IS_CLOSED(self) \
(!self->buffer || \
(!self->buffer ? !self->buffer : \
(self->fast_closed_checks \
? _PyFileIO_closed(self->raw) \
: buffered_closed(self)))
Expand Down
Loading