[Pyrex] C-API implementation in Pyrex 0.9.6

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Oct 20 05:31:04 CEST 2007


Stefan Behnel wrote:
> Hmm, I didn't test that, could you explain why this should be a problem?

When you 'cimport export', Pyrex reads the .pxd
file and builds a symbol table for it. If you
then 'cimport package.export', and Pyrex doesn't
realise it's actually the same module, it reads
the .pxd again and builds another symbol table
for it with a second copy of everything defined
in it.

Since Pyrex performs static type checking, this
can lead to puzzling things such as a variable
(effectively) declared as type 'export.Foo' not
being assignable to one declared as type
'package.export.Foo'.

It's the same sort of thing as happens in Python
if you somehow end up importing a module twice
under different names, and issubclass(x, Foo)
turns out to be unexpectedly false because you
have two different classes called Foo when you
thought you only had one.

Try something like this and see what happens:

# export.pxd

cdef struct Foo:
   int spam

# importer.pyx

cimport package.export
cimport export

def test():
   cdef package.export.Foo a
   cdef export.Foo b
   a = b

--
Greg



More information about the Pyrex mailing list