mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-78465: Fix error message for cls.__new__(cls, ...) where cls is not instantiable (GH-135981)
Previous error message suggested to use cls.__new__(), which obviously does not work. Now the error message is the same as for cls(...).
This commit is contained in:
parent
f3aec60d7a
commit
c45f4f3ebe
5 changed files with 11 additions and 9 deletions
|
@ -10020,6 +10020,11 @@ tp_new_wrapper(PyObject *self, PyObject *args, PyObject *kwds)
|
|||
/* If staticbase is NULL now, it is a really weird type.
|
||||
In the spirit of backwards compatibility (?), just shut up. */
|
||||
if (staticbase && staticbase->tp_new != type->tp_new) {
|
||||
if (staticbase->tp_new == NULL) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"cannot create '%s' instances", subtype->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%s.__new__(%s) is not safe, use %s.__new__()",
|
||||
type->tp_name,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue