mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
gh-113212: Improve error message & document zero-arg super inside nested functions and generator expressions (GH-113307)
This commit is contained in:
parent
237e2cff00
commit
4a3d2419bb
4 changed files with 51 additions and 3 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue