Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6a42bd6

Browse files
committed
Make super() internal errors RuntimeError instead of SystemError (closes #15839)
1 parent 9f16e44 commit 6a42bd6

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

Lib/test/test_super.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,21 @@ def f():
115115
return __class__
116116
self.assertIs(X.f(), X)
117117

118+
def test_obscure_super_errors(self):
119+
def f():
120+
super()
121+
self.assertRaises(RuntimeError, f)
122+
def f(x):
123+
del x
124+
super()
125+
self.assertRaises(RuntimeError, f, None)
126+
class X:
127+
def f(x):
128+
nonlocal __class__
129+
del __class__
130+
super()
131+
self.assertRaises(RuntimeError, X().f)
132+
118133

119134
def test_main():
120135
support.run_unittest(TestSuper)

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ What's New in Python 3.3.1
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #15839: Convert SystemErrors in super() to RuntimeErrors.
14+
1315
- Issue #15801: Make sure mappings passed to '%' formatting are actually
1416
subscriptable.
1517

Objects/typeobject.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6497,18 +6497,18 @@ super_init(PyObject *self, PyObject *args, PyObject *kwds)
64976497
PyCodeObject *co = f->f_code;
64986498
Py_ssize_t i, n;
64996499
if (co == NULL) {
6500-
PyErr_SetString(PyExc_SystemError,
6500+
PyErr_SetString(PyExc_RuntimeError,
65016501
"super(): no code object");
65026502
return -1;
65036503
}
65046504
if (co->co_argcount == 0) {
6505-
PyErr_SetString(PyExc_SystemError,
6505+
PyErr_SetString(PyExc_RuntimeError,
65066506
"super(): no arguments");
65076507
return -1;
65086508
}
65096509
obj = f->f_localsplus[0];
65106510
if (obj == NULL) {
6511-
PyErr_SetString(PyExc_SystemError,
6511+
PyErr_SetString(PyExc_RuntimeError,
65126512
"super(): arg[0] deleted");
65136513
return -1;
65146514
}
@@ -6527,18 +6527,18 @@ super_init(PyObject *self, PyObject *args, PyObject *kwds)
65276527
PyTuple_GET_SIZE(co->co_cellvars) + i;
65286528
PyObject *cell = f->f_localsplus[index];
65296529
if (cell == NULL || !PyCell_Check(cell)) {
6530-
PyErr_SetString(PyExc_SystemError,
6530+
PyErr_SetString(PyExc_RuntimeError,
65316531
"super(): bad __class__ cell");
65326532
return -1;
65336533
}
65346534
type = (PyTypeObject *) PyCell_GET(cell);
65356535
if (type == NULL) {
6536-
PyErr_SetString(PyExc_SystemError,
6536+
PyErr_SetString(PyExc_RuntimeError,
65376537
"super(): empty __class__ cell");
65386538
return -1;
65396539
}
65406540
if (!PyType_Check(type)) {
6541-
PyErr_Format(PyExc_SystemError,
6541+
PyErr_Format(PyExc_RuntimeError,
65426542
"super(): __class__ is not a type (%s)",
65436543
Py_TYPE(type)->tp_name);
65446544
return -1;
@@ -6547,7 +6547,7 @@ super_init(PyObject *self, PyObject *args, PyObject *kwds)
65476547
}
65486548
}
65496549
if (type == NULL) {
6550-
PyErr_SetString(PyExc_SystemError,
6550+
PyErr_SetString(PyExc_RuntimeError,
65516551
"super(): __class__ cell not found");
65526552
return -1;
65536553
}

0 commit comments

Comments
 (0)