[Cython] redefining PyIndex_Check
Hi, instead of overriding an existing definition of "PyIndex_Check" like this: """ +#if PY_VERSION_HEX < 0x0205 +/* NumPy headers define PyIndex_Check incorrectly */ +#undef PyIndex_Check +#define PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && !PyComplex_Check(o)) +#endif """ which may or may not have come from NumPy, shouldn't we be using our own definition of a "__Pyx_PyIndex_Check" in our code instead? Stefan ___ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel
Re: [Cython] redefining PyIndex_Check
On 11 November 2012 08:12, Stefan Behnel wrote: > Hi, > > instead of overriding an existing definition of "PyIndex_Check" like this: > > """ > +#if PY_VERSION_HEX < 0x0205 > +/* NumPy headers define PyIndex_Check incorrectly */ > +#undef PyIndex_Check > +#define PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && > !PyComplex_Check(o)) > +#endif > """ > > which may or may not have come from NumPy, shouldn't we be using our own > definition of a "__Pyx_PyIndex_Check" in our code instead? > > Stefan > ___ > cython-devel mailing list > cython-devel@python.org > http://mail.python.org/mailman/listinfo/cython-devel I thought about that, but then people do expect PyIndex_Check to work when they cimport it from cpython. But this fix doesn't really address that either, it just works if you use memoryviews (it's more of a quick and dirty hack, this fix needs to be associated with the cimport of numpy). Maybe we should use __Pyx_PyIndex_Check internally, and define PyIndex_Check like we do now for user convenience, and let numpy break it? Mark ___ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel
Re: [Cython] redefining PyIndex_Check
mark florisson, 11.11.2012 12:26: > On 11 November 2012 08:12, Stefan Behnel wrote: >> instead of overriding an existing definition of "PyIndex_Check" like this: >> >> """ >> +#if PY_VERSION_HEX < 0x0205 >> +/* NumPy headers define PyIndex_Check incorrectly */ >> +#undef PyIndex_Check >> +#define PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && >> !PyComplex_Check(o)) >> +#endif >> """ >> >> which may or may not have come from NumPy, shouldn't we be using our own >> definition of a "__Pyx_PyIndex_Check" in our code instead? > > I thought about that, but then people do expect PyIndex_Check to work > when they cimport it from cpython. But this fix doesn't really address > that either, it just works if you use memoryviews (it's more of a > quick and dirty hack, this fix needs to be associated with the cimport > of numpy). > > Maybe we should use __Pyx_PyIndex_Check internally, and define > PyIndex_Check like we do now for user convenience, and let numpy break > it? +1 for all three points. Cython's own code should always be safe, users won't normally use that function anyway and NumPy would only break their code in Py2.4, which is sufficiently rarely used. BTW, has anyone brought this to the attention of the NumPy developers yet? They might want to fix their definition. Stefan ___ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel
Re: [Cython] redefining PyIndex_Check
On 11 November 2012 13:04, Stefan Behnel wrote: > mark florisson, 11.11.2012 12:26: >> On 11 November 2012 08:12, Stefan Behnel wrote: >>> instead of overriding an existing definition of "PyIndex_Check" like this: >>> >>> """ >>> +#if PY_VERSION_HEX < 0x0205 >>> +/* NumPy headers define PyIndex_Check incorrectly */ >>> +#undef PyIndex_Check >>> +#define PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && >>> !PyComplex_Check(o)) >>> +#endif >>> """ >>> >>> which may or may not have come from NumPy, shouldn't we be using our own >>> definition of a "__Pyx_PyIndex_Check" in our code instead? >> >> I thought about that, but then people do expect PyIndex_Check to work >> when they cimport it from cpython. But this fix doesn't really address >> that either, it just works if you use memoryviews (it's more of a >> quick and dirty hack, this fix needs to be associated with the cimport >> of numpy). >> >> Maybe we should use __Pyx_PyIndex_Check internally, and define >> PyIndex_Check like we do now for user convenience, and let numpy break >> it? > > +1 for all three points. Cython's own code should always be safe, users > won't normally use that function anyway and NumPy would only break their > code in Py2.4, which is sufficiently rarely used. Great, I'm on it. On second consideration, it's better to not break it at all, and just define it to __Pyx_PyIndex_Check in the pxd. > BTW, has anyone brought this to the attention of the NumPy developers yet? > They might want to fix their definition. I haven't yet, maybe I'll just do a PR for such a trivial fix -- although maybe they have a reason for their definition. > Stefan > > ___ > cython-devel mailing list > cython-devel@python.org > http://mail.python.org/mailman/listinfo/cython-devel ___ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel
Re: [Cython] redefining PyIndex_Check
On 11 November 2012 14:09, mark florisson wrote: > On 11 November 2012 13:04, Stefan Behnel wrote: >> mark florisson, 11.11.2012 12:26: >>> On 11 November 2012 08:12, Stefan Behnel wrote: instead of overriding an existing definition of "PyIndex_Check" like this: """ +#if PY_VERSION_HEX < 0x0205 +/* NumPy headers define PyIndex_Check incorrectly */ +#undef PyIndex_Check +#define PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && !PyComplex_Check(o)) +#endif """ which may or may not have come from NumPy, shouldn't we be using our own definition of a "__Pyx_PyIndex_Check" in our code instead? >>> >>> I thought about that, but then people do expect PyIndex_Check to work >>> when they cimport it from cpython. But this fix doesn't really address >>> that either, it just works if you use memoryviews (it's more of a >>> quick and dirty hack, this fix needs to be associated with the cimport >>> of numpy). >>> >>> Maybe we should use __Pyx_PyIndex_Check internally, and define >>> PyIndex_Check like we do now for user convenience, and let numpy break >>> it? >> >> +1 for all three points. Cython's own code should always be safe, users >> won't normally use that function anyway and NumPy would only break their >> code in Py2.4, which is sufficiently rarely used. > > Great, I'm on it. On second consideration, it's better to not break it > at all, and just define it to __Pyx_PyIndex_Check in the pxd. > >> BTW, has anyone brought this to the attention of the NumPy developers yet? >> They might want to fix their definition. > > I haven't yet, maybe I'll just do a PR for such a trivial fix -- > although maybe they have a reason for their definition. Great, Pauli fixed it a while back: https://github.com/numpy/numpy/pull/307 >> Stefan >> >> ___ >> cython-devel mailing list >> cython-devel@python.org >> http://mail.python.org/mailman/listinfo/cython-devel ___ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel
Re: [Cython] Any more fixes for 0.17.2?
Stefan Behnel, 04.11.2012 00:22: > the 0.17 branch has gained a couple of fixes, so I'd like to release a > 0.17.2 some time next week. In case you have other things to add to it > within the next few days, please do, or send a quick reply if you'd like to > have more time. Ok, the branch looks good. Any more changes before the release? Stefan ___ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel