summaryrefslogtreecommitdiffstats
path: root/Objects/typeobject.c
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2006-06-18 22:17:29 (GMT)
committerGeorg Brandl <georg@python.org>2006-06-18 22:17:29 (GMT)
commitccff78525889fe2fa1a3512c4084a407994f9ce3 (patch)
treed8f3482e702a64e147455613d56bf471042e1e62 /Objects/typeobject.c
parent066769c3073fb080e5ba0b68499e726c56d509c0 (diff)
downloadcpython-ccff78525889fe2fa1a3512c4084a407994f9ce3.zip
cpython-ccff78525889fe2fa1a3512c4084a407994f9ce3.tar.gz
cpython-ccff78525889fe2fa1a3512c4084a407994f9ce3.tar.bz2
Patch #1507676: improve exception messages in abstract.c, object.c and typeobject.c.
Diffstat (limited to 'Objects/typeobject.c')
-rw-r--r--Objects/typeobject.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 0881ab1..439676f 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -1470,8 +1470,9 @@ subtype_setdict(PyObject *obj, PyObject *value, void *context)
return -1;
}
if (value != NULL && !PyDict_Check(value)) {
- PyErr_SetString(PyExc_TypeError,
- "__dict__ must be set to a dictionary");
+ PyErr_Format(PyExc_TypeError,
+ "__dict__ must be set to a dictionary, "
+ "not a '%.200s'", value->ob_type->tp_name);
return -1;
}
dict = *dictptr;
@@ -1534,8 +1535,9 @@ valid_identifier(PyObject *s)
Py_ssize_t i, n;
if (!PyString_Check(s)) {
- PyErr_SetString(PyExc_TypeError,
- "__slots__ must be strings");
+ PyErr_Format(PyExc_TypeError,
+ "__slots__ items must be strings, not '%.200s'",
+ s->ob_type->tp_name);
return 0;
}
p = (unsigned char *) PyString_AS_STRING(s);
@@ -2575,8 +2577,9 @@ reduce_2(PyObject *obj)
args = PyObject_CallObject(getnewargs, NULL);
Py_DECREF(getnewargs);
if (args != NULL && !PyTuple_Check(args)) {
- PyErr_SetString(PyExc_TypeError,
- "__getnewargs__ should return a tuple");
+ PyErr_Format(PyExc_TypeError,
+ "__getnewargs__ should return a tuple, "
+ "not '%.200s'", args->ob_type->tp_name);
goto end;
}
}
@@ -4352,8 +4355,9 @@ slot_nb_index(PyObject *self)
result = temp->ob_type->tp_as_number->nb_index(temp);
}
else {
- PyErr_SetString(PyExc_TypeError,
- "__index__ must return an int or a long");
+ PyErr_Format(PyExc_TypeError,
+ "__index__ must return an int or a long, "
+ "not '%.200s'", temp->ob_type->tp_name);
result = -1;
}
Py_DECREF(temp);
@@ -4564,8 +4568,9 @@ slot_tp_hash(PyObject *self)
func = lookup_method(self, "__cmp__", &cmp_str);
}
if (func != NULL) {
+ PyErr_Format(PyExc_TypeError, "unhashable type: '%.200s'",
+ self->ob_type->tp_name);
Py_DECREF(func);
- PyErr_SetString(PyExc_TypeError, "unhashable type");
return -1;
}
PyErr_Clear();
@@ -4742,8 +4747,9 @@ slot_tp_iter(PyObject *self)
PyErr_Clear();
func = lookup_method(self, "__getitem__", &getitem_str);
if (func == NULL) {
- PyErr_SetString(PyExc_TypeError,
- "iteration over non-sequence");
+ PyErr_Format(PyExc_TypeError,
+ "'%.200s' object is not iterable",
+ self->ob_type->tp_name);
return NULL;
}
Py_DECREF(func);
@@ -4816,8 +4822,9 @@ slot_tp_init(PyObject *self, PyObject *args, PyObject *kwds)
if (res == NULL)
return -1;
if (res != Py_None) {
- PyErr_SetString(PyExc_TypeError,
- "__init__() should return None");
+ PyErr_Format(PyExc_TypeError,
+ "__init__() should return None, not '%.200s'",
+ res->ob_type->tp_name);
Py_DECREF(res);
return -1;
}