On Tue, Sep 28, 2010 at 10:14 AM, Matěj Laitl <[email protected]> wrote: > Hi! > I have problems with cython dealing with following example case (python 2.6.5, > cython 0.13): > > 2 cdef classes, Pdf and GaussPdf; GaussPdf inherits Pdf. Both are written in > pure python file pdfs.py and use augmentation pdfs.pxd for cythoning. > (attached) Both have just cpdef methods, GaussPdf overrides 4 of 5 Pdf's > methods. When tested as Python code, everything is okay, but when compiled > using cython, I get following error: > >>>> from pdfs import Pdf >>>> p = Pdf() >>>> p.shape() > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "pdfs.py", line 15, in pybayes.pdfs.Pdf.shape (pybayes/pdfs.c:975) > TypeError: Cannot convert pybayes.pdfs.Pdf to pybayes.pdfs.GaussPdf > > It should have thrown NotImplementedError, not TypeError! > > I think the problem is in the generated C code. First couple of lines from > python wrapper around Pdf.mean() C function: > > static PyObject *__pyx_pf_7pybayes_4pdfs_3Pdf_shape(PyObject *__pyx_v_self, > CYTHON_UNUSED PyObject *unused) { > PyObject *__pyx_r = NULL; > PyObject *__pyx_t_1 = NULL; > __Pyx_RefNannySetupContext("shape"); > __Pyx_XDECREF(__pyx_r); > if (!(likely(((__pyx_v_self) == Py_None) || > likely(__Pyx_TypeTest(__pyx_v_self, __pyx_ptype_7pybayes_4pdfs_GaussPdf))))) > {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; > goto > __pyx_L1_error;} > > The last line is #975. Notice the __Pyx_TypeTest(..self, ..GaussPdf) - I would > expect it would read __Pyx_TypeTest(..self, .Pdf) instead! > > Also, vtabstruct for Pdf seems strange (it contains GaussPdf methods), but > that may be correct inheritance magic. > > Is this really a bug in Cython, or am I doing something completely wrong?
No, this looks like a bug on our side. Clearly the pure mode + augmented .pxd is insufficiently tested. I have an idea where it might be happening too... - Robert _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
