summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-10-22 04:12:44 (GMT)
committerGuido van Rossum <guido@python.org>2001-10-22 04:12:44 (GMT)
commit5c66a26dee41853a9ce43b75965cc16b8e34aef0 (patch)
treed303f21f83853154614174dc1b6ed1891aa68315 /Objects
parent279e74457351f4b6686d2b592f6662393bc8d757 (diff)
downloadcpython-5c66a26dee41853a9ce43b75965cc16b8e34aef0.zip
cpython-5c66a26dee41853a9ce43b75965cc16b8e34aef0.tar.gz
cpython-5c66a26dee41853a9ce43b75965cc16b8e34aef0.tar.bz2
Make the error message for unsupported operand types cleaner, in
response to a message by Laura Creighton on c.l.py. E.g. >>> 0+'' TypeError: unsupported operand types for +: 'int' and 'str' (previously this did not mention the operand types) >>> ''+0 TypeError: cannot concatenate 'str' and 'int' objects
Diffstat (limited to 'Objects')
-rw-r--r--Objects/abstract.c34
-rw-r--r--Objects/stringobject.c2
2 files changed, 28 insertions, 8 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 24b09f5..8a715c8 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -383,8 +383,12 @@ binary_op(PyObject *v, PyObject *w, const int op_slot, const char *op_name)
PyObject *result = binary_op1(v, w, op_slot);
if (result == Py_NotImplemented) {
Py_DECREF(Py_NotImplemented);
- PyErr_Format(PyExc_TypeError,
- "unsupported operand type(s) for %s", op_name);
+ PyErr_Format(
+ PyExc_TypeError,
+ "unsupported operand type(s) for %s: '%s' and '%s'",
+ op_name,
+ v->ob_type->tp_name,
+ w->ob_type->tp_name);
return NULL;
}
return result;
@@ -533,9 +537,22 @@ ternary_op(PyObject *v,
if (c >= 0)
return x;
}
-
- PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for %s",
- op_name);
+
+ if (z == Py_None)
+ PyErr_Format(
+ PyExc_TypeError,
+ "unsupported operand type(s) for ** or pow(): "
+ "'%s' and '%s'",
+ v->ob_type->tp_name,
+ w->ob_type->tp_name);
+ else
+ PyErr_Format(
+ PyExc_TypeError,
+ "unsupported operand type(s) for pow(): "
+ "'%s', '%s', '%s'",
+ v->ob_type->tp_name,
+ w->ob_type->tp_name,
+ z->ob_type->tp_name);
return NULL;
}
@@ -566,8 +583,11 @@ PyNumber_Add(PyObject *v, PyObject *w)
result = (*m->sq_concat)(v, w);
}
else {
- PyErr_SetString(PyExc_TypeError,
- "unsupported operand types for +");
+ PyErr_Format(
+ PyExc_TypeError,
+ "unsupported operand types for +: '%s' and '%s'",
+ v->ob_type->tp_name,
+ w->ob_type->tp_name);
result = NULL;
}
}
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 0a3155e..74c4b52 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -691,7 +691,7 @@ string_concat(register PyStringObject *a, register PyObject *bb)
return PyUnicode_Concat((PyObject *)a, bb);
#endif
PyErr_Format(PyExc_TypeError,
- "cannot add type \"%.200s\" to string",
+ "cannot concatenate 'str' and '%.200s' objects",
bb->ob_type->tp_name);
return NULL;
}