|
17 | 17 | type=object_rprimitive, |
18 | 18 | src='PyDict_Type') |
19 | 19 |
|
| 20 | +# Construct an empty dictionary. |
| 21 | +dict_new_op = custom_op( |
| 22 | + arg_types=[], |
| 23 | + return_type=dict_rprimitive, |
| 24 | + c_function_name='PyDict_New', |
| 25 | + error_kind=ERR_MAGIC) |
| 26 | + |
| 27 | +# Construct a dictionary from keys and values. |
| 28 | +# Positional argument is the number of key-value pairs |
| 29 | +# Variable arguments are (key1, value1, ..., keyN, valueN). |
| 30 | +dict_build_op = custom_op( |
| 31 | + arg_types=[c_pyssize_t_rprimitive], |
| 32 | + return_type=dict_rprimitive, |
| 33 | + c_function_name='CPyDict_Build', |
| 34 | + error_kind=ERR_MAGIC, |
| 35 | + var_arg_type=object_rprimitive) |
| 36 | + |
| 37 | +# Construct a dictionary from another dictionary. |
| 38 | +function_op( |
| 39 | + name='builtins.dict', |
| 40 | + arg_types=[dict_rprimitive], |
| 41 | + return_type=dict_rprimitive, |
| 42 | + c_function_name='PyDict_Copy', |
| 43 | + error_kind=ERR_MAGIC, |
| 44 | + priority=2) |
| 45 | + |
| 46 | +# Generic one-argument dict constructor: dict(obj) |
| 47 | +function_op( |
| 48 | + name='builtins.dict', |
| 49 | + arg_types=[object_rprimitive], |
| 50 | + return_type=dict_rprimitive, |
| 51 | + c_function_name='CPyDict_FromAny', |
| 52 | + error_kind=ERR_MAGIC) |
| 53 | + |
20 | 54 | # dict[key] |
21 | 55 | dict_get_item_op = method_op( |
22 | 56 | name='__getitem__', |
|
84 | 118 | c_function_name='CPyDict_GetWithNone', |
85 | 119 | error_kind=ERR_MAGIC) |
86 | 120 |
|
87 | | -# Construct an empty dictionary. |
88 | | -dict_new_op = custom_op( |
89 | | - arg_types=[], |
90 | | - return_type=dict_rprimitive, |
91 | | - c_function_name='PyDict_New', |
| 121 | +# dict.setdefault(key, default) |
| 122 | +method_op( |
| 123 | + name='setdefault', |
| 124 | + arg_types=[dict_rprimitive, object_rprimitive, object_rprimitive], |
| 125 | + return_type=object_rprimitive, |
| 126 | + c_function_name='CPyDict_SetDefault', |
| 127 | + is_borrowed=True, |
92 | 128 | error_kind=ERR_MAGIC) |
93 | 129 |
|
94 | | -# Construct a dictionary from keys and values. |
95 | | -# Positional argument is the number of key-value pairs |
96 | | -# Variable arguments are (key1, value1, ..., keyN, valueN). |
97 | | -dict_build_op = custom_op( |
98 | | - arg_types=[c_pyssize_t_rprimitive], |
99 | | - return_type=dict_rprimitive, |
100 | | - c_function_name='CPyDict_Build', |
101 | | - error_kind=ERR_MAGIC, |
102 | | - var_arg_type=object_rprimitive) |
103 | | - |
104 | | -# Construct a dictionary from another dictionary. |
105 | | -function_op( |
106 | | - name='builtins.dict', |
107 | | - arg_types=[dict_rprimitive], |
108 | | - return_type=dict_rprimitive, |
109 | | - c_function_name='PyDict_Copy', |
110 | | - error_kind=ERR_MAGIC, |
111 | | - priority=2) |
112 | | - |
113 | | -# Generic one-argument dict constructor: dict(obj) |
114 | | -function_op( |
115 | | - name='builtins.dict', |
116 | | - arg_types=[object_rprimitive], |
117 | | - return_type=dict_rprimitive, |
118 | | - c_function_name='CPyDict_FromAny', |
| 130 | +# dict.setdefault(key) |
| 131 | +method_op( |
| 132 | + name='setdefault', |
| 133 | + arg_types=[dict_rprimitive, object_rprimitive], |
| 134 | + return_type=object_rprimitive, |
| 135 | + c_function_name='CPyDict_SetDefaultWithNone', |
| 136 | + is_borrowed=True, |
119 | 137 | error_kind=ERR_MAGIC) |
120 | 138 |
|
121 | 139 | # dict.keys() |
|
0 commit comments