[Cython] negative integer -> unsigned integer, TypeError or OverflowError?
Stefan Behnel
stefan_ml at behnel.de
Fri Feb 6 20:00:09 CET 2009
Hi,
Lisandro Dalcin wrote:
> Core CPython is not consistent about this. What should we do in
> Cython? Should we report this to Python-Dev?
>
> Long story:
>
> In core CPython (svn trunk), at Objects/longobjects.c, you should see
> that in almost all cases OverflowError is raise. But see this one:
>
> int
> _PyLong_AsByteArray(PyLongObject* v,
> unsigned char* bytes, size_t n,
> int little_endian, int is_signed)
> {
> <...>
> if (!is_signed) {
> PyErr_SetString(PyExc_TypeError,
> "can't convert negative long to unsigned");
> return -1;
> }
> <...>
> }
Raising an OverflowError sounds like the right thing. If CPython raises it
in almost all cases, it's ok if Cython does that, too.
Still, asking on python-dev would allow them to take a decision and maybe
even fix the above discrepancy.
Stefan
More information about the Cython-dev
mailing list