Commit 12a04392 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

objdict: Implement __getitem__ method.

parent 263853ef
......@@ -123,6 +123,12 @@ STATIC bool dict_store_item(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
return true;
}
STATIC mp_obj_t dict_getitem(mp_obj_t lhs_in, mp_obj_t rhs_in) {
return dict_binary_op(MP_BINARY_OP_SUBSCR, lhs_in, rhs_in);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(dict_getitem_obj, dict_getitem);
/******************************************************************************/
/* dict iterator */
......@@ -481,6 +487,7 @@ STATIC const mp_map_elem_t dict_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_setdefault), (mp_obj_t)&dict_setdefault_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_update), (mp_obj_t)&dict_update_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_values), (mp_obj_t)&dict_values_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR___getitem__), (mp_obj_t)&dict_getitem_obj },
};
STATIC MP_DEFINE_CONST_DICT(dict_locals_dict, dict_locals_dict_table);
......
......@@ -12,3 +12,5 @@ print(d['1'], d['2'], d['3'])
d2 = dict(d)
print('2' in d2)
print(id(d) != id(d2), d == d2)
print(d.__getitem__('2'))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment