I'm on Greg's side. As there are real performance issues, 'typecheck'
should be supported in Cython. My use cases are mainly (though
actually a small buch of calls) for checking against cdef classes.
Aaron, you could do the following: Add the snippet below in a
'typecheck.pxi' file, then include it with 'include "typecheck.pxi"'
at the beginning of every .pyx file you want to have 'typecheck´
available. If Cython ever get built-in support for typecheck, then you
should just remove the pxi file and the places where it is included. I
just wrote this for you, but also just included it in my petsc4py
project (I had typecheck, but actually implemented calling
PyObject_IsInstance).
cdef extern from "Python.h":
ctypedef struct PyTypeObject
int PyObject_TypeCheck(object, PyTypeObject*)
cdef inline bint typecheck(object ob, object tp):
return PyObject_TypeCheck(ob, <PyTypeObject*>tp)
Let me know if this hackery worked for you.
Regards,
On Mon, Sep 22, 2008 at 9:53 PM, Aaron DeVore <[EMAIL PROTECTED]> wrote:
> So how do I go about getting PyObject_TypeCheck working?
>
> -Aaron
>
> On Mon, Sep 22, 2008 at 4:30 PM, Greg Ewing <[EMAIL PROTECTED]>
> wrote:
>>
>> Aaron DeVore wrote:
>>
>> > In most cases I'm checking for whatever is generated by cdef class Foo:
>> > ... I'm not sure if that would be a type or a subclass.
>>
>> It's a type, aka new-style class, so both PyObject_TypeCheck
>> and PyObject_IsInstance will work equally well, and they
>> will both accept either that exact type or a subclass of
>> it.
>>
>> PyObject_TypeCheck is probably a bit faster, since it doesn't
>> have to worry about dealing with old-style classes and
>> instances.
>>
>> --
>> Greg
>> _______________________________________________
>> Cython-dev mailing list
>> [email protected]
>> http://codespeak.net/mailman/listinfo/cython-dev
>
>
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
>
>
--
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev