diff --git a/py/builtin.h b/py/builtin.h index 337524899a..caca71b523 100644 --- a/py/builtin.h +++ b/py/builtin.h @@ -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; diff --git a/py/objdict.c b/py/objdict.c index 1bebf08647..19d9ae9e9f 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -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); diff --git a/py/opmethods.c b/py/opmethods.c index f0f19b6dfb..27415fef9b 100644 --- a/py/opmethods.c +++ b/py/opmethods.c @@ -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); diff --git a/py/qstrdefs.h b/py/qstrdefs.h index df383b776c..c2d538d1f1 100644 --- a/py/qstrdefs.h +++ b/py/qstrdefs.h @@ -24,6 +24,7 @@ Q(__len__) Q(__iter__) Q(__getitem__) Q(__setitem__) +Q(__delitem__) Q(__add__) Q(__sub__) Q(__repr__)