summaryrefslogtreecommitdiffstats
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 048f9a8..92db31f 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -14057,14 +14057,21 @@ formatchar(PyObject *v)
if (PyUnicode_GET_LENGTH(v) == 1) {
return PyUnicode_READ_CHAR(v, 0);
}
- goto onError;
+ PyErr_Format(PyExc_TypeError,
+ "%%c requires an int or a unicode character, "
+ "not a string of length %zd",
+ PyUnicode_GET_LENGTH(v));
+ return (Py_UCS4) -1;
}
else {
int overflow;
long x = PyLong_AsLongAndOverflow(v, &overflow);
if (x == -1 && PyErr_Occurred()) {
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
- goto onError;
+ PyErr_Format(PyExc_TypeError,
+ "%%c requires an int or a unicode character, not %T",
+ v);
+ return (Py_UCS4) -1;
}
return (Py_UCS4) -1;
}
@@ -14078,11 +14085,6 @@ formatchar(PyObject *v)
return (Py_UCS4) x;
}
-
- onError:
- PyErr_SetString(PyExc_TypeError,
- "%c requires int or char");
- return (Py_UCS4) -1;
}
/* Parse options of an argument: flags, width, precision.