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 21, 2023
1 parent 4afa7be commit 0f7d134
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions Objects/typeobject.c
Expand Up @@ -10389,9 +10389,20 @@ 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 0f7d134

Please sign in to comment.