gh-113212: Improve error message & document zero-arg super inside nested functions and generator expressions (GH-113307)

This commit is contained in:
Yan Yanchii 2023-12-22 16:12:08 +01:00 committed by GitHub
parent 237e2cff00
commit 4a3d2419bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 3 deletions

View file

@ -10404,9 +10404,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;
}