On Wed, Mar 4, 2020 at 2:58 AM Steven D'Aprano <[email protected]> wrote:
> I don't know enough about the Python internals to give a definitive
> answer, but I'm assuming/hoping that there is a single, or at most a
> few, places in the interpreter that matches up arguments to formal
> parameters, and if there's a discrepency it currently raises TypeError.
> PyCall sounds promising :-)
>
In my experience, it's sprinkled all over the place. For example, here are
the pertinent chunks of one of our functions that converts VAX floats to
IEEE...
static PyObject *vax_data_floats(PyObject *self, PyObject **args,
Py_ssize_t nargs)
{
if (nargs != 2) {
PyErr_Format(PyExc_TypeError, "floats: expected 2 arguments,
'bytes' and 'count'");
return NULL;
}
...
if (!PyLong_Check(py_count)) {
PyErr_Format(PyExc_TypeError, "floats: second argument must be an
int");
return NULL;
}
...
if (count*(Py_ssize_t)sizeof(float) > bytes_size) {
PyErr_Format(PyExc_TypeError,
"floats: argument 2 is larger than data (only %d bytes
for requested %d floats)",
bytes_size,
count);
return NULL;
}
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/CRYO5NA463YGDLSTQDTFS3DWGBXVWDX2/
Code of Conduct: http://python.org/psf/codeofconduct/