summaryrefslogtreecommitdiffstatshomepage
path: root/py/objdict.c
diff options
context:
space:
mode:
authorJohn R. Lenton <jlenton@gmail.com>2014-01-14 23:58:05 +0000
committerJohn R. Lenton <jlenton@gmail.com>2014-01-14 23:58:05 +0000
commitff8007c7d6497b108e8abe80ab3311945a03fe52 (patch)
treee2f6974d6476cc46b7414ba0626cb519142c3e3d /py/objdict.c
parent9daa78943e58602f74c89a2b5b1ed225f4ccf6cc (diff)
parentc6920d31e2b03205fe2851f74a6a4b48d0165608 (diff)
downloadmicropython-ff8007c7d6497b108e8abe80ab3311945a03fe52.tar.gz
micropython-ff8007c7d6497b108e8abe80ab3311945a03fe52.zip
Merge remote-tracking branch 'upstream/master' into builtins
Diffstat (limited to 'py/objdict.c')
-rw-r--r--py/objdict.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/py/objdict.c b/py/objdict.c
index 6dbb1f316b..e164ed74ca 100644
--- a/py/objdict.c
+++ b/py/objdict.c
@@ -57,6 +57,12 @@ static mp_obj_t dict_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
return elem->value;
}
}
+ case RT_COMPARE_OP_IN:
+ case RT_COMPARE_OP_NOT_IN:
+ {
+ mp_map_elem_t *elem = mp_map_lookup(&o->map, rhs_in, MP_MAP_LOOKUP);
+ return MP_BOOL((op == RT_COMPARE_OP_IN) ^ (elem == NULL));
+ }
default:
// op not supported
return NULL;
@@ -362,10 +368,20 @@ static void dict_view_print(void (*print)(void *env, const char *fmt, ...), void
print(env, "])");
}
+static mp_obj_t dict_view_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
+ /* only supported for the 'keys' kind until sets and dicts are refactored */
+ mp_obj_dict_view_t *o = lhs_in;
+ if (o->kind != MP_DICT_VIEW_KEYS) return NULL;
+ if (op != RT_COMPARE_OP_IN && op != RT_COMPARE_OP_NOT_IN) return NULL;
+ return dict_binary_op(op, o->dict, rhs_in);
+}
+
+
static const mp_obj_type_t dict_view_type = {
{ &mp_const_type },
"dict_view",
.print = dict_view_print,
+ .binary_op = dict_view_binary_op,
.getiter = dict_view_getiter,
};