summaryrefslogtreecommitdiffstats
path: root/Objects/object.c
diff options
context:
space:
mode:
authorJames Hilton-Balfe <gobot1234yt@gmail.com>2023-07-22 00:24:26 (GMT)
committerGitHub <noreply@github.com>2023-07-22 00:24:26 (GMT)
commitcdeb1a6caad5e3067f01d6058238803b8517f9de (patch)
tree952950c42ffd25901e8b9319120f5e57ab9507bd /Objects/object.c
parent41ca16455188db806bfc7037058e8ecff2755e6c (diff)
downloadcpython-cdeb1a6caad5e3067f01d6058238803b8517f9de.zip
cpython-cdeb1a6caad5e3067f01d6058238803b8517f9de.tar.gz
cpython-cdeb1a6caad5e3067f01d6058238803b8517f9de.tar.bz2
gh-96663: Add a better error message for __dict__-less classes setattr (#103232)
Diffstat (limited to 'Objects/object.c')
-rw-r--r--Objects/object.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/Objects/object.c b/Objects/object.c
index d30e048..bfbc871 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -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);