[Pyrex] A patch for cimport

Stefan Behnel stefan_ml at behnel.de
Wed Jan 23 11:35:18 CET 2008


Hi,

this has actually been discussed before.

Dan Gindikin wrote:
> If you have the following setup:
>     
>     pkg/__init__.py
> 
>     pkg/main.pyx
>     
>         cimport submod
>        
>     pkg/submod.pyx
> 
>         cdef cfunc(): pass
>        
>     pkg/submod.pxd
> 
>         cdef cfunc()
>        
> and you do
> 
>     % python -c "import pkg.main"
>     
> you will get an import error.
> 
> This happens because "cimport submod" in main.pyx causes a call to
> "__Pyx_ImportType", which in turn calls "__Pyx_ImportModule", which does
> not
> honor the package context, and thus tries to import "submod" instead of
> "pkg.submod".

The way Pyrex deals with this is to use "pkg.submod.pyx" as file name. That
way, Pyrex know the FQMN at compile time.

Stefan




More information about the Pyrex mailing list