Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
12a04392
Commit
12a04392
authored
Apr 11, 2014
by
Paul Sokolovsky
Browse files
objdict: Implement __getitem__ method.
parent
263853ef
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/objdict.c
View file @
12a04392
...
...
@@ -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
);
...
...
tests/basics/dict2.py
View file @
12a04392
...
...
@@ -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'
))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment