mirror of
https://github.com/python/cpython.git
synced 2025-07-30 22:54:16 +00:00
Patch #1507676: improve exception messages in abstract.c, object.c and typeobject.c.
This commit is contained in:
parent
066769c307
commit
ccff785258
4 changed files with 82 additions and 65 deletions
|
@ -1068,7 +1068,8 @@ PyObject_Hash(PyObject *v)
|
|||
return _Py_HashPointer(v); /* Use address as hash value */
|
||||
}
|
||||
/* If there's a cmp but no hash defined, the object can't be hashed */
|
||||
PyErr_SetString(PyExc_TypeError, "unhashable type");
|
||||
PyErr_Format(PyExc_TypeError, "unhashable type: '%.200s'",
|
||||
v->ob_type->tp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1133,8 +1134,9 @@ PyObject_GetAttr(PyObject *v, PyObject *name)
|
|||
else
|
||||
#endif
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"attribute name must be string");
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"attribute name must be string, not '%.200s'",
|
||||
name->ob_type->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
@ -1179,8 +1181,9 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
|
|||
else
|
||||
#endif
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"attribute name must be string");
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"attribute name must be string, not '%.200s'",
|
||||
name->ob_type->tp_name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -1277,8 +1280,9 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
|
|||
else
|
||||
#endif
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"attribute name must be string");
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"attribute name must be string, not '%.200s'",
|
||||
name->ob_type->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
@ -1399,8 +1403,9 @@ PyObject_GenericSetAttr(PyObject *obj, PyObject *name, PyObject *value)
|
|||
else
|
||||
#endif
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"attribute name must be string");
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"attribute name must be string, not '%.200s'",
|
||||
name->ob_type->tp_name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -1450,7 +1455,7 @@ PyObject_GenericSetAttr(PyObject *obj, PyObject *name, PyObject *value)
|
|||
|
||||
if (descr == NULL) {
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
"'%.50s' object has no attribute '%.400s'",
|
||||
"'%.100s' object has no attribute '%.200s'",
|
||||
tp->tp_name, PyString_AS_STRING(name));
|
||||
goto done;
|
||||
}
|
||||
|
@ -1773,8 +1778,9 @@ PyObject_Dir(PyObject *arg)
|
|||
|
||||
assert(result);
|
||||
if (!PyList_Check(result)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Expected keys() to be a list.");
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"Expected keys() to be a list, not '%.200s'",
|
||||
result->ob_type->tp_name);
|
||||
goto error;
|
||||
}
|
||||
if (PyList_Sort(result) != 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue