mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-96663: Add a better error message for __dict__-less classes setattr (#103232)
This commit is contained in:
parent
41ca164551
commit
cdeb1a6caa
4 changed files with 32 additions and 5 deletions
|
@ -1576,9 +1576,18 @@ _PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name,
|
|||
}
|
||||
if (dictptr == NULL) {
|
||||
if (descr == NULL) {
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
"'%.100s' object has no attribute '%U'",
|
||||
tp->tp_name, name);
|
||||
if (tp->tp_setattro == PyObject_GenericSetAttr) {
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
"'%.100s' object has no attribute '%U' and no "
|
||||
"__dict__ for setting new attributes",
|
||||
tp->tp_name, name);
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
"'%.100s' object has no attribute '%U'",
|
||||
tp->tp_name, name);
|
||||
}
|
||||
set_attribute_error_context(obj, name);
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
|
@ -1611,6 +1620,7 @@ _PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name,
|
|||
"'%.100s' object has no attribute '%U'",
|
||||
tp->tp_name, name);
|
||||
}
|
||||
set_attribute_error_context(obj, name);
|
||||
}
|
||||
done:
|
||||
Py_XDECREF(descr);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue