]> granicus.if.org Git - python/commitdiff
Make super() internal errors RuntimeError instead of SystemError (closes #15839)
authorBenjamin Peterson <benjamin@python.org>
Sun, 2 Sep 2012 03:04:38 +0000 (23:04 -0400)
committerBenjamin Peterson <benjamin@python.org>
Sun, 2 Sep 2012 03:04:38 +0000 (23:04 -0400)
Lib/test/test_super.py
Misc/NEWS
Objects/typeobject.c

index 32eb1c090917cdbafea5c0d1b55c34c3f9114623..f6469cf26392d726bc3e26d999c2c92a8c98f32e 100644 (file)
@@ -115,6 +115,21 @@ class TestSuper(unittest.TestCase):
                 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)
index fef71cfdb8a9547e0e1a394e5ecf55f9e19289f8..2af87eed7b107fa039c3748c053d528d86c8389b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@ What's New in Python 3.3.1
 Core and Builtins
 -----------------
 
+- Issue #15839: Convert SystemErrors in super() to RuntimeErrors.
+
 - Issue #15801: Make sure mappings passed to '%' formatting are actually
   subscriptable.
 
index a357ced22017917ce58af32c20c84c39d33c1fd3..bc01b0da85b8e9b8f531c23450b5379e1c21b44f 100644 (file)
@@ -6497,18 +6497,18 @@ super_init(PyObject *self, PyObject *args, PyObject *kwds)
         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 @@ super_init(PyObject *self, PyObject *args, PyObject *kwds)
                     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 @@ super_init(PyObject *self, PyObject *args, PyObject *kwds)
             }
         }
         if (type == NULL) {
-            PyErr_SetString(PyExc_SystemError,
+            PyErr_SetString(PyExc_RuntimeError,
                             "super(): __class__ cell not found");
             return -1;
         }