[Python-checkins] r52787 - in python/trunk: Lib/test/test_format.py Misc/NEWS Objects/listobject.c Objects/stringobject.c Objects/tupleobject.c
georg.brandl
python-checkins at python.org
Sun Nov 19 09:48:31 CET 2006
Author: georg.brandl
Date: Sun Nov 19 09:48:30 2006
New Revision: 52787
Modified:
python/trunk/Lib/test/test_format.py
python/trunk/Misc/NEWS
python/trunk/Objects/listobject.c
python/trunk/Objects/stringobject.c
python/trunk/Objects/tupleobject.c
Log:
Patch [ 1586791 ] better error msgs for some TypeErrors
Modified: python/trunk/Lib/test/test_format.py
==============================================================================
--- python/trunk/Lib/test/test_format.py (original)
+++ python/trunk/Lib/test/test_format.py Sun Nov 19 09:48:30 2006
@@ -219,8 +219,8 @@
test_exc(unicode('abc %\u3000','raw-unicode-escape'), 1, ValueError,
"unsupported format character '?' (0x3000) at index 5")
-test_exc('%d', '1', TypeError, "int argument required")
-test_exc('%g', '1', TypeError, "float argument required")
+test_exc('%d', '1', TypeError, "int argument required, not str")
+test_exc('%g', '1', TypeError, "float argument required, not str")
test_exc('no format', '1', TypeError,
"not all arguments converted during string formatting")
test_exc('no format', u'1', TypeError,
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Sun Nov 19 09:48:30 2006
@@ -12,6 +12,9 @@
Core and builtins
-----------------
+- Patch #1586791: Better exception messages for some operations on strings,
+ tuples and lists.
+
- Bug #1067760: Deprecate passing floats to file.seek.
- Bug #1591996: Correctly forward exception in instance_contains().
Modified: python/trunk/Objects/listobject.c
==============================================================================
--- python/trunk/Objects/listobject.c (original)
+++ python/trunk/Objects/listobject.c Sun Nov 19 09:48:30 2006
@@ -946,9 +946,10 @@
if (res == NULL)
return -1;
if (!PyInt_Check(res)) {
+ PyErr_Format(PyExc_TypeError,
+ "comparison function must return int, not %.200s",
+ res->ob_type->tp_name);
Py_DECREF(res);
- PyErr_SetString(PyExc_TypeError,
- "comparison function must return int");
return -1;
}
i = PyInt_AsLong(res);
@@ -2491,8 +2492,9 @@
}
}
else {
- PyErr_SetString(PyExc_TypeError,
- "list indices must be integers");
+ PyErr_Format(PyExc_TypeError,
+ "list indices must be integers, not %.200s",
+ item->ob_type->tp_name);
return NULL;
}
}
@@ -2635,8 +2637,9 @@
}
}
else {
- PyErr_SetString(PyExc_TypeError,
- "list indices must be integers");
+ PyErr_Format(PyExc_TypeError,
+ "list indices must be integers, not %.200s",
+ item->ob_type->tp_name);
return -1;
}
}
Modified: python/trunk/Objects/stringobject.c
==============================================================================
--- python/trunk/Objects/stringobject.c (original)
+++ python/trunk/Objects/stringobject.c Sun Nov 19 09:48:30 2006
@@ -1071,8 +1071,9 @@
return PyUnicode_Contains(str_obj, sub_obj);
#endif
if (!PyString_Check(sub_obj)) {
- PyErr_SetString(PyExc_TypeError,
- "'in <string>' requires string as left operand");
+ PyErr_Format(PyExc_TypeError,
+ "'in <string>' requires string as left operand, "
+ "not %.200s", sub_obj->ob_type->tp_name);
return -1;
}
}
@@ -1240,8 +1241,9 @@
}
}
else {
- PyErr_SetString(PyExc_TypeError,
- "string indices must be integers");
+ PyErr_Format(PyExc_TypeError,
+ "string indices must be integers, not %.200s",
+ item->ob_type->tp_name);
return NULL;
}
}
@@ -4148,7 +4150,8 @@
double x;
x = PyFloat_AsDouble(v);
if (x == -1.0 && PyErr_Occurred()) {
- PyErr_SetString(PyExc_TypeError, "float argument required");
+ PyErr_Format(PyExc_TypeError, "float argument required, "
+ "not %.200s", v->ob_type->tp_name);
return -1;
}
if (prec < 0)
@@ -4343,7 +4346,8 @@
x = PyInt_AsLong(v);
if (x == -1 && PyErr_Occurred()) {
- PyErr_SetString(PyExc_TypeError, "int argument required");
+ PyErr_Format(PyExc_TypeError, "int argument required, not %.200s",
+ v->ob_type->tp_name);
return -1;
}
if (x < 0 && type == 'u') {
Modified: python/trunk/Objects/tupleobject.c
==============================================================================
--- python/trunk/Objects/tupleobject.c (original)
+++ python/trunk/Objects/tupleobject.c Sun Nov 19 09:48:30 2006
@@ -620,8 +620,9 @@
}
}
else {
- PyErr_SetString(PyExc_TypeError,
- "tuple indices must be integers");
+ PyErr_Format(PyExc_TypeError,
+ "tuple indices must be integers, not %.200s",
+ item->ob_type->tp_name);
return NULL;
}
}
More information about the Python-checkins
mailing list