[Cython] Intra-package reference not working with cimport

Stephane DROUARD stephane.drouard at st.com
Mon Nov 3 12:44:54 CET 2008


Hello,

Intra-package reference (http://docs.python.org/tutorial/modules.html#intra-package-references) does not work with cimport.

foo.py:
def foo():
    pass

bar.py:
import foo
foo.foo()

If I move foo.py and bar.py into a package and import pkg.bar, it works under Python as well as under Cython.

But if I "cimport foo" (cdef foo), it works when not in a package, but fails to import foo when in pkg.

Looking at the generated code, I see that "import foo" is mapped to
  PyObject_CallFunction(__import__, ...
using the module as globals (why not using PyImport_ImportModuleEx()?),

whereas "cimport foo" uses PyImport_Import(), that lets globals to NULL, so the issue.

Is there a reason that cimport is mapped differently?

Cheers,
Stephane



More information about the Cython-dev mailing list