logo       

Re: Circular cimports: msg#00018

python.pyrex

Subject: Re: Circular cimports

In C/C++, I believe this problem would be solved like this:

**matrix.h**
#ifndef MATRIX_H
#define MATRIX_H

/* declarations here */
#endif

**matrix.c**
#include "matrix.h"

/* implementation here */

Is there an equivalent to #ifndef in Pyrex?  Or is there any other solution to my problem?
I'm building a little math library in Pyrex, and I'm having trouble with some circular cimports.  I'll post short excerpts from my various files, then show the error that I'm getting when I try to use one of the modules.

**matrix.pxd**
cdef class Matrix:
    cdef float m[4][4]

**matrix.pyx**
cimport vector

cdef class Matrix:
    ### a bunch of methods, including ones that create or manipulate Vector objects ###

**vector.pxd**
cdef class Vector:
    cdef float x, y, z, w

**vector.pyx**
cimport matrix

cdef class Vector:
    ### a bunch of methods, including one that has a Matrix argument ###

After building the Pyrex modules into .pyd files, I run a test module.  The first line imports the matrix module and throws this error:

Traceback (most recent call last):
  File "C:\Development\SFStratPrototype\math3d\matrixTest.py", line 1, in ?
    import matrix
  File "vector.pxd", line 1, in matrix
    cdef class Vector:
  File "matrix.pxd", line 1, in vector
    cdef class Matrix:
AttributeError: 'module' object has no attribute 'Matrix'
Press any key to continue . . .

It doesn't seem to like how the modules cimport each other.  I can't see any way to eliminate this circular reference, so what can I do to fix this error?

- Mike Wyatt

_______________________________________________ Pyrex mailing list Pyrex@xxxxxxxxxxxxxxxxx http://lists.copyleft.no/mailman/listinfo/pyrex
_______________________________________________
Pyrex mailing list
Pyrex@xxxxxxxxxxxxxxxxx
http://lists.copyleft.no/mailman/listinfo/pyrex
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise