Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
BUG: don't pollute public namespace with customized PyIndex_Check on Py2.4 #307
Move compatibility #define for PyIndex_Check on Python 2.4 to a private compat header
The problem is that including the public Numpy header "arrayobject.h" defines a compatibility wrapper for "PyIndex_Check" on Python 2.4. Moreover, this compatibility wrapper functions incorrectly... This #define probably should not be in the public namespace, as it already causes problems with Cython on Py2.4 (which we hit into in Scipy release):
The second commit moves all non Py3-stuff out of npy_3compat.h to another, more private compat header, for stylistic reasons (mainly because #defining
A question with this PR is --- is there 3rd party software out there that relies on Numpy headers defining the otherwise missing PyIndex_Check being defined, and do we care. I'd say we don't care, this seems like a corner case, and the current behavior in Numpy is wrong.
It might be time to deprecate Python 2.4 support as well. The thinking behind the PyIndex_Check being set to 0 is that before 2.4 there is no Index attribute and so no object can be an "index" object. This is the correct behavior. It is Cython that is doing the wrong thing here.
In practice, it depends on why people are using PyIndex_Check in the code. An index is anything that can be interpreted as an integer. A number is quite a bit more general than that. Code might be trying to access the tp_index slot in the number structure after doing a PyIndex_Check. You have to return 0 if there is no such slot (like in Python 2.4).
Cython code should not be using PyIndex_Check as it if were the same thing as PyNumber_Check. That is a mistake. But, I'm not going to try and fix that problem, as they must not be accessing the tp_index slot directly.
It's fine to make our version private, though --- especially because it's just a Python 2.4 thing.
As far as I see, Cython is using
EDIT: uhh, or maybe the "correct" compatibility mode should be PyInt_Check on Py2.4. I'm not sure what Cython should do here...