Skip to content

Commit cd94b38

Browse files
committed
objdict: Add __setitem__.
1 parent 86a0304 commit cd94b38

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

py/builtin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ MP_DECLARE_CONST_FUN_OBJ(mp_namedtuple_obj);
3737

3838
MP_DECLARE_CONST_FUN_OBJ(mp_op_contains_obj);
3939
MP_DECLARE_CONST_FUN_OBJ(mp_op_getitem_obj);
40+
MP_DECLARE_CONST_FUN_OBJ(mp_op_setitem_obj);
4041

4142
extern const mp_obj_module_t mp_module___main__;
4243
extern const mp_obj_module_t mp_module_array;

py/objdict.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ STATIC const mp_map_elem_t dict_locals_dict_table[] = {
497497
{ MP_OBJ_NEW_QSTR(MP_QSTR_update), (mp_obj_t)&dict_update_obj },
498498
{ MP_OBJ_NEW_QSTR(MP_QSTR_values), (mp_obj_t)&dict_values_obj },
499499
{ MP_OBJ_NEW_QSTR(MP_QSTR___getitem__), (mp_obj_t)&mp_op_getitem_obj },
500+
{ MP_OBJ_NEW_QSTR(MP_QSTR___setitem__), (mp_obj_t)&mp_op_setitem_obj },
500501
};
501502

502503
STATIC MP_DEFINE_CONST_DICT(dict_locals_dict, dict_locals_dict_table);

py/opmethods.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ STATIC mp_obj_t op_getitem(mp_obj_t lhs_in, mp_obj_t rhs_in) {
1313
}
1414
MP_DEFINE_CONST_FUN_OBJ_2(mp_op_getitem_obj, op_getitem);
1515

16+
STATIC mp_obj_t op_setitem(mp_obj_t self_in, mp_obj_t key_in, mp_obj_t value_in) {
17+
mp_store_subscr(self_in, key_in, value_in);
18+
return mp_const_none;
19+
}
20+
MP_DEFINE_CONST_FUN_OBJ_3(mp_op_setitem_obj, op_setitem);
21+
1622
STATIC mp_obj_t op_contains(mp_obj_t lhs_in, mp_obj_t rhs_in) {
1723
mp_obj_type_t *type = mp_obj_get_type(lhs_in);
1824
return type->binary_op(MP_BINARY_OP_IN, lhs_in, rhs_in);

0 commit comments

Comments
 (0)