Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions Lib/test/test_exception_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,15 @@ def test_blockingioerror(self):
e = BlockingIOError(*args[:n])
with self.assertRaises(AttributeError):
e.characters_written
with self.assertRaises(AttributeError):
del e.characters_written
e = BlockingIOError("a", "b", 3)
self.assertEqual(e.characters_written, 3)
e.characters_written = 5
self.assertEqual(e.characters_written, 5)
del e.characters_written
with self.assertRaises(AttributeError):
e.characters_written


class ExplicitSubclassingTest(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a SystemError when delete the characters_written attribute of an OSError.
8 changes: 8 additions & 0 deletions Objects/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,14 @@ OSError_written_get(PyOSErrorObject *self, void *context)
static int
OSError_written_set(PyOSErrorObject *self, PyObject *arg, void *context)
{
if (arg == NULL) {
if (self->written == -1) {
PyErr_SetString(PyExc_AttributeError, "characters_written");
return -1;
}
self->written = -1;
return 0;
}
Py_ssize_t n;
n = PyNumber_AsSsize_t(arg, PyExc_ValueError);
if (n == -1 && PyErr_Occurred())
Expand Down