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

Charles R Harris charlesr.harris@gmail....
Tue Jun 2 01:32:43 CDT 2009


On Mon, Jun 1, 2009 at 11:58 PM, David Cournapeau <
david@ar.media.kyoto-u.ac.jp> wrote:

> 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
>

Hmm, makes me think even more that the python code is the buggy one here.
Why should it depend on inheritance from the int type? I mean, isn't that
kind of limiting? All they need to know is that it can be *converted* to a
python integer. It's like duck typing is being replaced by strict typing.
Because it's faster to interpret (duh).

Of course, I may have no idea what I'm talking about.


>
> 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.


There speaks the build guy ;)


> 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...
>

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090602/21aea54a/attachment-0001.html 


More information about the Numpy-discussion mailing list