1# mode: run 2# tag: builtins 3 4cimport cython 5 6@cython.test_assert_path_exists( 7 '//ReturnStatNode//PythonCapiCallNode') 8def unbound_dict_get(d): 9 """ 10 >>> unbound_dict_get({}) 11 >>> unbound_dict_get({1:2}) 12 2 13 """ 14 get = dict.get 15 return get(d, 1) 16 17 18@cython.test_assert_path_exists( 19 '//ReturnStatNode//PythonCapiCallNode') 20def bound_dict_get(dict d): 21 """ 22 >>> bound_dict_get({}) 23 >>> bound_dict_get({1:2}) 24 2 25 """ 26 get = d.get 27 return get(1) 28 29 30@cython.test_fail_if_path_exists( 31 '//ReturnStatNode//PythonCapiCallNode') 32@cython.test_assert_path_exists( 33 '//ReturnStatNode//PyMethodCallNode') 34def bound_dict_get_reassign(dict d): 35 """ 36 >>> bound_dict_get_reassign({}) 37 >>> bound_dict_get_reassign({1:2}) 38 2 39 """ 40 get = d.get 41 d = {1: 3} 42 return get(1) 43 44 45@cython.test_assert_path_exists( 46 '//PythonCapiCallNode//NameNode[@name="l"]') 47def unbound_list_sort(list l): 48 """ 49 >>> unbound_list_sort([1, 3, 2]) 50 [1, 2, 3] 51 >>> unbound_list_sort([1, 3, 2]) 52 [1, 2, 3] 53 """ 54 sort = list.sort 55 sort(l) 56 return l 57 58 59@cython.test_assert_path_exists( 60 '//PythonCapiCallNode//NameNode[@name="l"]') 61def bound_list_sort(list l): 62 """ 63 >>> bound_list_sort([1, 3, 2]) 64 [1, 2, 3] 65 >>> bound_list_sort([1, 3, 2]) 66 [1, 2, 3] 67 """ 68 sort = l.sort 69 sort() 70 return l 71 72 73@cython.test_fail_if_path_exists( 74 '//PythonCapiCallNode') 75def bound_list_sort_reassign(list l): 76 """ 77 >>> bound_list_sort_reassign([1, 3, 2]) 78 [3, 2, 1] 79 >>> bound_list_sort_reassign([1, 3, 2]) 80 [3, 2, 1] 81 """ 82 sort = l.sort 83 l = [3, 2, 1] 84 sort() 85 return l 86