Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@cython.test_assert_path_exists('//PythonCapiCallNode')
@cython.locals(d=dict)
def setdefault2(d, key, value):
"""
>>> d = {}
>>> setdefault2(d, 1, 2)
2
>>> len(d)
1
>>> setdefault2(d, 1, 2)
2
>>> len(d)
1
>>> l = setdefault2(d, 2, [])
>>> len(d)
2
>>> l.append(1)
@cython.test_assert_path_exists(
"//BoolNode",
)
@cython.test_fail_if_path_exists(
"//PrimaryCmpNode",
"//MulNode",
"//ListNode//IntNode",
)
def combined():
"""
>>> combined()
True
"""
return 5 in 100 * [1, 2] * 0 or 5 not in 100 * [] * 10
@cython.test_assert_path_exists(
"//BoolNode",
)
@cython.test_fail_if_path_exists(
"//PrimaryCmpNode",
"//MulNode",
"//ListNode//IntNode",
)
def in_mult_list():
"""
>>> in_mult_list()
False
"""
return 5 in 100 * [1, 2] * 0
@cython.test_assert_path_exists("//CFuncDeclaratorNode//IntNode[@value = '-1']")
@cython.cfunc
@cython.returns(cython.long)
@cython.exceptval(-1)
def cdef_except(x):
if x == 0:
raise ValueError
return x+1
@cython.test_assert_path_exists(
'//IntNode[@value = "2"]',
'//IntNode[@value = "4"]',
'//IntNode[@value = "5"]',
'//IntNode[@value = "7"]',
'//BoolBinopNode//PrimaryCmpNode',
'//BoolBinopNode[.//PrimaryCmpNode//IntNode[@value = "4"] and .//PrimaryCmpNode//IntNode[@value = "5"]]',
'//PrimaryCmpNode[.//IntNode[@value = "2"] and .//IntNode[@value = "4"]]',
'//PrimaryCmpNode[.//IntNode[@value = "5"] and .//IntNode[@value = "7"]]',
)
@cython.test_fail_if_path_exists(
'//IntNode[@value = "1"]',
'//IntNode[@value = "8"]',
'//PrimaryCmpNode[.//IntNode[@value = "4"] and .//IntNode[@value = "5"]]',
'//PrimaryCmpNode[.//IntNode[@value = "2"] and .//IntNode[@value = "7"]]',
'//BoolNode',
)
@cython.test_assert_path_exists('//PythonCapiCallNode')
@cython.locals(d=dict)
def setdefault1(d, key):
"""
>>> d = {}
>>> setdefault1(d, 1)
>>> len(d)
1
>>> setdefault1(d, 1)
>>> len(d)
1
>>> d[1]
>>> setdefault1(d, Unhashable())
Traceback (most recent call last):
TypeError: I am not hashable
>>> len(d)
1
@cython.test_assert_path_exists('//SimpleCallNode[@function.type.is_cfunction = True]')
@cython.test_fail_if_path_exists('//SimpleCallNode[@function.type.is_builtin_type = True]')
def call_str(arg):
"""
>>> print(call_str('TEST'))
STR
"""
return str(arg)
@cython.test_assert_path_exists("//CFuncDeclaratorNode//IntNode[@value = '-1']")
@cython.ccall
@cython.returns(cython.long)
@cython.exceptval(-1)
def ccall_except(x):
"""
>>> ccall_except(41)
42
>>> ccall_except(0)
Traceback (most recent call last):
ValueError
"""
if x == 0:
raise ValueError
return x+1
@cython.test_assert_path_exists('//ReturnStatNode//ForInStatNode//TupleNode')
@cython.test_fail_if_path_exists('//ReturnStatNode//ForInStatNode//ListNode')
def listcomp_over_multiplied_constant_list():
"""
>>> listcomp_over_multiplied_constant_list()
[[], [1, 2, 3], [1, 2, 3, 1, 2, 3], [1, 2, 3, 1, 2, 3, 1, 2, 3], [1, 2, 3, 1, 2, 3]]
"""
return [
[i for i in [1, 2, 3] * 0],
[i for i in [1, 2, 3] * 1],
[i for i in [1, 2, 3] * 2],
[i for i in [1, 2, 3] * 3],
[i for i in [1, 2, 3] * 2],
]
@cython.test_assert_path_exists("//CFuncDeclaratorNode//IntNode[@value = '-1']")
@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