objdict: Add __delitem__.

This commit is contained in:
Paul Sokolovsky 2014-04-13 23:55:59 +03:00
parent cd94b384a3
commit 14de114ba8
4 changed files with 9 additions and 0 deletions

View File

@ -38,6 +38,7 @@ MP_DECLARE_CONST_FUN_OBJ(mp_namedtuple_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_op_contains_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_op_getitem_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_op_setitem_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_op_delitem_obj);
extern const mp_obj_module_t mp_module___main__;
extern const mp_obj_module_t mp_module_array;

View File

@ -498,6 +498,7 @@ STATIC const mp_map_elem_t dict_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_values), (mp_obj_t)&dict_values_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR___getitem__), (mp_obj_t)&mp_op_getitem_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR___setitem__), (mp_obj_t)&mp_op_setitem_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR___delitem__), (mp_obj_t)&mp_op_delitem_obj },
};
STATIC MP_DEFINE_CONST_DICT(dict_locals_dict, dict_locals_dict_table);

View File

@ -19,6 +19,12 @@ STATIC mp_obj_t op_setitem(mp_obj_t self_in, mp_obj_t key_in, mp_obj_t value_in)
}
MP_DEFINE_CONST_FUN_OBJ_3(mp_op_setitem_obj, op_setitem);
STATIC mp_obj_t op_delitem(mp_obj_t self_in, mp_obj_t key_in) {
mp_store_subscr(self_in, key_in, MP_OBJ_NULL);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(mp_op_delitem_obj, op_delitem);
STATIC mp_obj_t op_contains(mp_obj_t lhs_in, mp_obj_t rhs_in) {
mp_obj_type_t *type = mp_obj_get_type(lhs_in);
return type->binary_op(MP_BINARY_OP_IN, lhs_in, rhs_in);

View File

@ -24,6 +24,7 @@ Q(__len__)
Q(__iter__)
Q(__getitem__)
Q(__setitem__)
Q(__delitem__)
Q(__add__)
Q(__sub__)
Q(__repr__)