Skip to content

Commit

Permalink
pythongh-113212: Improve super() error message.
Browse files Browse the repository at this point in the history
  • Loading branch information
WolframAlph committed Dec 22, 2023
1 parent 4afa7be commit 478cd1e
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -10389,9 +10389,22 @@ supercheck(PyTypeObject *type, PyObject *obj)
Py_XDECREF(class_attr);
}

PyErr_SetString(PyExc_TypeError,
"super(type, obj): "
"obj must be an instance or subtype of type");
const char *type_or_instance, *obj_str;

if (PyType_Check(obj)) {
type_or_instance = "type";
obj_str = ((PyTypeObject*)obj)->tp_name;
}
else {
type_or_instance = "instance of";
obj_str = Py_TYPE(obj)->tp_name;
}

PyErr_Format(PyExc_TypeError,
"super(type, obj): obj (%s %.200s) is not "
"an instance or subtype of type (%.200s).",
type_or_instance, obj_str, type->tp_name);

return NULL;
}

Expand Down

0 comments on commit 478cd1e

Please sign in to comment.