[Python-checkins] bpo-35504: Fix a SystemError when delete the characters_written attribute of an OSError. (GH-11172)

Serhiy Storchaka webhook-mailer at python.org
Mon Dec 17 09:43:21 EST 2018


https://github.com/python/cpython/commit/e2af34fcf84b41189b54e1f2912faded5daabaca
commit: e2af34fcf84b41189b54e1f2912faded5daabaca
branch: master
author: Serhiy Storchaka <storchaka at gmail.com>
committer: GitHub <noreply at github.com>
date: 2018-12-17T16:43:14+02:00
summary:

bpo-35504: Fix a SystemError when delete the characters_written attribute of an OSError. (GH-11172)

files:
A Misc/NEWS.d/next/Core and Builtins/2018-12-15-00-47-41.bpo-35504.9gVuen.rst
M Lib/test/test_exception_hierarchy.py
M Objects/exceptions.c

diff --git a/Lib/test/test_exception_hierarchy.py b/Lib/test/test_exception_hierarchy.py
index 864959679094..43b4af84039c 100644
--- a/Lib/test/test_exception_hierarchy.py
+++ b/Lib/test/test_exception_hierarchy.py
@@ -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):
diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-12-15-00-47-41.bpo-35504.9gVuen.rst b/Misc/NEWS.d/next/Core and Builtins/2018-12-15-00-47-41.bpo-35504.9gVuen.rst
new file mode 100644
index 000000000000..622b50ca62da
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2018-12-15-00-47-41.bpo-35504.9gVuen.rst	
@@ -0,0 +1 @@
+Fixed a SystemError when delete the characters_written attribute of an OSError.
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 05578d4a6aad..002a602373d7 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -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())



More information about the Python-checkins mailing list