[Python-checkins] cpython: Make super() internal errors RuntimeError instead of SystemError (closes #15839)

benjamin.peterson python-checkins at python.org
Sun Sep 2 05:04:46 CEST 2012


http://hg.python.org/cpython/rev/e2e4a0a49d2e
changeset:   78832:e2e4a0a49d2e
user:        Benjamin Peterson <benjamin at python.org>
date:        Sat Sep 01 23:04:38 2012 -0400
summary:
  Make super() internal errors RuntimeError instead of SystemError (closes #15839)

files:
  Lib/test/test_super.py |  15 +++++++++++++++
  Misc/NEWS              |   2 ++
  Objects/typeobject.c   |  14 +++++++-------
  3 files changed, 24 insertions(+), 7 deletions(-)


diff --git a/Lib/test/test_super.py b/Lib/test/test_super.py
--- a/Lib/test/test_super.py
+++ b/Lib/test/test_super.py
@@ -115,6 +115,21 @@
                 return __class__
         self.assertIs(X.f(), X)
 
+    def test_obscure_super_errors(self):
+        def f():
+            super()
+        self.assertRaises(RuntimeError, f)
+        def f(x):
+            del x
+            super()
+        self.assertRaises(RuntimeError, f, None)
+        class X:
+            def f(x):
+                nonlocal __class__
+                del __class__
+                super()
+        self.assertRaises(RuntimeError, X().f)
+
 
 def test_main():
     support.run_unittest(TestSuper)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@
 Core and Builtins
 -----------------
 
+- Issue #15839: Convert SystemErrors in super() to RuntimeErrors.
+
 - Issue #15801: Make sure mappings passed to '%' formatting are actually
   subscriptable.
 
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -6497,18 +6497,18 @@
         PyCodeObject *co = f->f_code;
         Py_ssize_t i, n;
         if (co == NULL) {
-            PyErr_SetString(PyExc_SystemError,
+            PyErr_SetString(PyExc_RuntimeError,
                             "super(): no code object");
             return -1;
         }
         if (co->co_argcount == 0) {
-            PyErr_SetString(PyExc_SystemError,
+            PyErr_SetString(PyExc_RuntimeError,
                             "super(): no arguments");
             return -1;
         }
         obj = f->f_localsplus[0];
         if (obj == NULL) {
-            PyErr_SetString(PyExc_SystemError,
+            PyErr_SetString(PyExc_RuntimeError,
                             "super(): arg[0] deleted");
             return -1;
         }
@@ -6527,18 +6527,18 @@
                     PyTuple_GET_SIZE(co->co_cellvars) + i;
                 PyObject *cell = f->f_localsplus[index];
                 if (cell == NULL || !PyCell_Check(cell)) {
-                    PyErr_SetString(PyExc_SystemError,
+                    PyErr_SetString(PyExc_RuntimeError,
                       "super(): bad __class__ cell");
                     return -1;
                 }
                 type = (PyTypeObject *) PyCell_GET(cell);
                 if (type == NULL) {
-                    PyErr_SetString(PyExc_SystemError,
+                    PyErr_SetString(PyExc_RuntimeError,
                       "super(): empty __class__ cell");
                     return -1;
                 }
                 if (!PyType_Check(type)) {
-                    PyErr_Format(PyExc_SystemError,
+                    PyErr_Format(PyExc_RuntimeError,
                       "super(): __class__ is not a type (%s)",
                       Py_TYPE(type)->tp_name);
                     return -1;
@@ -6547,7 +6547,7 @@
             }
         }
         if (type == NULL) {
-            PyErr_SetString(PyExc_SystemError,
+            PyErr_SetString(PyExc_RuntimeError,
                             "super(): __class__ cell not found");
             return -1;
         }

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list