1# mode: run
2# ticket: 1888
3
4PYTHON setup.py build_ext --inplace
5PYTHON -c "import a; a.test()"
6
7######## setup.py ########
8
9from Cython.Build.Dependencies import cythonize
10
11from distutils.core import setup
12
13setup(
14    ext_modules=cythonize("a.pyx"),
15)
16
17######## a.pxd ########
18
19cdef int do_stuff(int foo) except -1
20
21######## a.pyx ########
22
23cdef int do_stuff(int bar) except -1:
24    if bar == 0:
25        raise ValueError()
26    return bar
27
28
29cdef call_do_stuff(int x):
30    # The keyword argument name is surprising, but actually correct.
31    # The caller signature is defined by the .pxd file, not the implementation.
32    return do_stuff(foo=x)
33
34
35def test():
36    assert do_stuff(1) == 1
37    assert do_stuff(foo=1) == 1
38    assert call_do_stuff(1) == 1
39
40    try:
41        do_stuff(0)
42    except ValueError:
43        pass
44    else:
45        assert False, "exception not raised"
46
47    try:
48        call_do_stuff(0)
49    except ValueError:
50        pass
51    else:
52        assert False, "exception not raised"
53