[Python-Dev] How long the wrong type of argument should we limit (or not) in the error message (C-api)?
Vajrasky Kok
sky.kok at speaklikeaking.com
Sat Dec 14 05:56:06 CET 2013
Greetings,
When fixing/adding error message for wrong type of argument in C code,
I am always confused, how long the wrong type is the ideal?
The type of error message that I am talking about:
"Blabla() argument 1 must be integer not wrong_type".
We have inconsistency in CPython code, for example:
Python/sysmodule.c
===============
PyErr_Format(PyExc_TypeError,
"can't intern %.400s", s->ob_type->tp_name);
Modules/_json.c
============
PyErr_Format(PyExc_TypeError,
"first argument must be a string, not %.80s",
Py_TYPE(pystr)->tp_name);
Objects/typeobject.c
===============
PyErr_Format(PyExc_TypeError,
"can only assign string to %s.__name__, not '%s'",
type->tp_name, Py_TYPE(value)->tp_name);
So is it %.400s or %.80s or %s? I vote for %s.
Other thing is which one is more preferable? Py_TYPE(value)->tp_name
or value->ob_type->tp_name? I vote for Py_TYPE(value)->tp_name.
Or this is just a matter of taste?
Thank you.
Vajrasky Kok
More information about the Python-Dev
mailing list