Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@cython.ccall
@cython.returns(cython.double)
def c_call(x):
return x
@cython.ccall
@cython.returns(cython.long)
@cython.exceptval(-1, check=True)
def ccall_except_check(x):
"""
>>> ccall_except_check(41)
42
>>> ccall_except_check(-2)
-1
>>> ccall_except_check(0)
Traceback (most recent call last):
ValueError
"""
if x == 0:
raise ValueError
return x+1
@cython.ccall # cpdef => C return type
def test_return_type(n: cython.int) -> cython.double:
"""
>>> test_return_type(389)
389.0
"""
assert cython.typeof(n) == 'int', cython.typeof(n)
return n if is_compiled else float(n)
@cython.ccall
def c_call(x) -> cython.double:
return x
@cython.ccall
@cython.returns(cython.long)
@cython.exceptval(check=True)
def ccall_except_check_always(x):
"""
>>> ccall_except_check_always(41)
42
>>> ccall_except_check_always(0)
Traceback (most recent call last):
ValueError
"""
if x == 0:
raise ValueError
return x+1
@ccall
def meth(self):
return 0
@cython.ccall
def is_pythran_supported_type(type_):
pythran_supported = (
"is_pythran_expr", "is_int", "is_numeric", "is_float", "is_none", "is_complex")
return is_type(type_, pythran_supported) or is_pythran_expr(type_)
@cython.ccall
def is_pythran_expr(type_):
return type_.is_pythran_expr
@cython.ccall
def is_pythran_expr(type_):
return type_.is_pythran_expr
@cython.ccall
def is_pythran_supported_type(type_):
pythran_supported = (
"is_pythran_expr", "is_int", "is_numeric", "is_float", "is_none", "is_complex")
return is_type(type_, pythran_supported) or is_pythran_expr(type_)