mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
bpo-35504: Fix a SystemError when delete the characters_written attribute of an OSError. (GH-11172)
This commit is contained in:
parent
fae95874b7
commit
e2af34fcf8
3 changed files with 14 additions and 0 deletions
|
@ -150,10 +150,15 @@ class AttributesTest(unittest.TestCase):
|
||||||
e = BlockingIOError(*args[:n])
|
e = BlockingIOError(*args[:n])
|
||||||
with self.assertRaises(AttributeError):
|
with self.assertRaises(AttributeError):
|
||||||
e.characters_written
|
e.characters_written
|
||||||
|
with self.assertRaises(AttributeError):
|
||||||
|
del e.characters_written
|
||||||
e = BlockingIOError("a", "b", 3)
|
e = BlockingIOError("a", "b", 3)
|
||||||
self.assertEqual(e.characters_written, 3)
|
self.assertEqual(e.characters_written, 3)
|
||||||
e.characters_written = 5
|
e.characters_written = 5
|
||||||
self.assertEqual(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):
|
class ExplicitSubclassingTest(unittest.TestCase):
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fixed a SystemError when delete the characters_written attribute of an OSError.
|
|
@ -1196,6 +1196,14 @@ OSError_written_get(PyOSErrorObject *self, void *context)
|
||||||
static int
|
static int
|
||||||
OSError_written_set(PyOSErrorObject *self, PyObject *arg, void *context)
|
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;
|
Py_ssize_t n;
|
||||||
n = PyNumber_AsSsize_t(arg, PyExc_ValueError);
|
n = PyNumber_AsSsize_t(arg, PyExc_ValueError);
|
||||||
if (n == -1 && PyErr_Occurred())
|
if (n == -1 && PyErr_Occurred())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue