[Numpy-discussion] numpy.int32, type inheritance and tp_flags

David Cournapeau david@ar.media.kyoto-u.ac...
Tue Jun 2 00:58:38 CDT 2009


Charles R Harris wrote:
>
>
> On Mon, Jun 1, 2009 at 11:08 PM, David Cournapeau
> <david@ar.media.kyoto-u.ac.jp <mailto:david@ar.media.kyoto-u.ac.jp>>
> wrote:
>
>     Hi,
>
>        I have a question related to #1121
>     (http://projects.scipy.org/numpy/ticket/1121). With python 2.6,
>     PyInt_Check(a) if a is an instance of numpy.int32 does not work
>     anymore.
>     It think this is related to the python issue 2263
>
>
>     (http://bugs.python.org/issue2263), where the tp_flags has been
>     changed
>     for the python int object, change which influences PyInt_Check
>     behavior.
>
>
> It would be nice if the python folks would document
> Py_TPFLAGS_INT_SUBCLASS so we knew what it did. I also wonder if the
> problem with struct and the related bug with timeseries aren't python
> bugs. Shouldn't python be checking for conversion calls rather than an
> integer subclass?

I found this while walking through the python hg log:

http://www.mail-archive.com/python-dev@python.org/msg18140.html

As I understand it, that's basically an optimization for fast subclass
testing, and is indeed not documented. But instead of hard-coding the
additional flag for types which support this in numpy, I think it would
be better to have something which will not break again when another flag
is added to some types. Specially since related bugs are quite hard to
track. I don't know how to do it, though, as the python doc says that
inheriting tp_flags is tricky...

David


More information about the Numpy-discussion mailing list