1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
PYTHON setup.py build_ext --inplace
PYTHON -c "import a"
######## setup.py ########
from Cython.Build import cythonize
from distutils.core import setup
setup(
ext_modules = cythonize("*.pyx"),
)
######## other.pxd ########
cdef class A:
pass
cdef int foo(int)
######## other.pyx ########
cdef class A:
pass
cdef int foo(int a):
return a**2
######## pkg/__init__.py ########
######## pkg/sub.pxd ########
ctypedef int my_int
######## pkg/subpkg/__init__.py ########
######## pkg/subpkg/submod.pxd ########
ctypedef int my_int
######## a.pyx ########
from other cimport (
A,
foo,
)
print(A, foo(10))
cimport other
cdef call_fooptr(int (*fptr)(int)):
return fptr(10)
def call_other_foo():
x = other.foo # GH4000 - failed because other was untyped
return call_fooptr(x) # check that x is correctly resolved as a function pointer
print(other.A, other.foo(10), call_other_foo())
from pkg cimport sub
cdef sub.my_int a = 100
from pkg.subpkg cimport submod
|