[Python-Dev] cpython: PyUnicode_FromKindAndData() raises a ValueError if the kind is unknown
Victor Stinner
victor.stinner at haypocalc.com
Tue Oct 4 00:09:28 CEST 2011
> > - assert(0);
> > + PyErr_SetString(PyExc_ValueError, "invalid kind");
> >
> > return NULL;
> >
> > }
>
> Is that really a ValueError? It should only be a ValueError if the user
> could trigger that error. Otherwise it should be a SystemError.
You are right, ValueError is not best exception here. I used SystemError
instead: see my commit 721bb2e59815.
PyUnicode_FromFormat() does still use ValueError in PyUnicode_FromFormatV:
PyErr_SetString(PyExc_ValueError,
"incomplete format key");
PyErr_SetString(PyExc_ValueError,
"width too big");
PyErr_SetString(PyExc_ValueError,
"prec too big");
PyErr_SetString(PyExc_ValueError,
"incomplete format");
PyErr_Format(PyExc_ValueError,
"unsupported format character '%c' (0x%x) "
"at index %zd",
(31<=c && c<=126) ? (char)c : '?',
(int)c,
fmtpos - 1);
PyErr_Format(PyExc_ValueError,
"PyUnicode_FromFormatV() expects an ASCII-encoded format "
"string, got a non-ASCII byte: 0x%02x",
(unsigned char)*f);
Should we also replace them by SystemError? It might break backward
compatibility, but I do really hope that nobody relies on these errors ;-)
Victor
More information about the Python-Dev
mailing list