summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2014-03-21 13:38:46 (GMT)
committerEthan Furman <ethan@stoneleaf.us>2014-03-21 13:38:46 (GMT)
commit9ab748013b00d6873b07c15ce50927104f5ece63 (patch)
tree5d4fbd8b80ce56ce7f1ca41b4f09a8faa843f1f6 /Objects
parenta17d6780980f5c1ca940b5260edcec4cf103469c (diff)
downloadcpython-9ab748013b00d6873b07c15ce50927104f5ece63.zip
cpython-9ab748013b00d6873b07c15ce50927104f5ece63.tar.gz
cpython-9ab748013b00d6873b07c15ce50927104f5ece63.tar.bz2
Issue19995: more informative error message; spelling corrections; use operator.mod instead of __mod__
Diffstat (limited to 'Objects')
-rw-r--r--Objects/unicodeobject.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 87cc5c2..e38ded0 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -13986,11 +13986,13 @@ mainformatlong(PyObject *v,
if (!PyNumber_Check(v))
goto wrongtype;
- /* make sure number is a type of integer */
+ /* make sure number is a type of integer for o, x, and X */
if (!PyLong_Check(v)) {
if (type == 'o' || type == 'x' || type == 'X') {
iobj = PyNumber_Index(v);
if (iobj == NULL) {
+ if (PyErr_ExceptionMatches(PyExc_TypeError))
+ goto wrongtype;
return -1;
}
}
@@ -14052,10 +14054,23 @@ mainformatlong(PyObject *v,
return 0;
wrongtype:
- PyErr_Format(PyExc_TypeError,
- "%%%c format: a number is required, "
- "not %.200s",
- type, Py_TYPE(v)->tp_name);
+ switch(type)
+ {
+ case 'o':
+ case 'x':
+ case 'X':
+ PyErr_Format(PyExc_TypeError,
+ "%%%c format: an integer is required, "
+ "not %.200s",
+ type, Py_TYPE(v)->tp_name);
+ break;
+ default:
+ PyErr_Format(PyExc_TypeError,
+ "%%%c format: a number is required, "
+ "not %.200s",
+ type, Py_TYPE(v)->tp_name);
+ break;
+ }
return -1;
}