Lisandro Dalcin wrote:
> Well, to do it the right way, nb_int it should take precedence if the
> type fits in a C int, or if it fits in a "signed long" but not
> "unsigned long". It seems that I was lazy, though I've actually tried
> to maintain the implementation of _Pyx_PyNumber_Int() simple and make
> it take a single argument (like the one in core CPython). I'll try to
> review my work and provide a patch

Thanks!


> though I'm not sure if further
> work will pay that much... For core CPython types, the only case where
> all this can have some impact in for float -> int conversion.

... plus, all of this will go away in Py3 anyway. So, don't invest too much
time, but if you can get it right, I think it would make things more robust
and consistent.


> As I've started to work on a patch, let put it clear case by case...
> 
> Python 2
> ----------
> a) if only __int__(), fill as "nb_int = __int__" and "nb_long = NULL"
> b) if only __long__(), fill as "nb_int = __long__" and "nb_long = NULL"
> c) if __int__() AND __long__(): fill as "nb_int = __int__" and
> "nb_long = __long__"
> 
> Python 3
> ----------
> a) if only __int__(), fill as "nb_int = __int__" and "nb_reserved = NULL"
> b) if only __long__(), fill as "nb_int = __long__" and "nb_reserved = NULL"

Fine so far.


> c) if __int__() AND __long__(): fill as "nb_int = __int__" and
> "nb_reserved = NULL"

I'm still unsure whether Py3 should prefer __long__ or __int__. I guess it
would be more consistent to use __int__ for nb_int in both Py2 and Py3, but
since nb_int *must* return a PyLong in Py3, it might be cleaner (and
easier?) to use __long__ instead.

If we use __int__ in Py3, I think it would make sense to raise a warning
only for case b). That would help users to get their code right. That might
be the best solution after all: use __int__ when available, support
__long__ only in Py2, and raise a warning when someone forgets to define
__int__ next to it.

Stefan

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to