Skip to content

Commit 036ad76

Browse files
committed
objset: Implement __contains__() op-method.
1 parent 1a37588 commit 036ad76

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

py/objset.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,13 @@ STATIC mp_obj_t set_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
423423
}
424424
}
425425

426+
// TODO: Move to common file
427+
STATIC mp_obj_t set_contains(mp_obj_t lhs_in, mp_obj_t rhs_in) {
428+
return set_binary_op(MP_BINARY_OP_IN, lhs_in, rhs_in);
429+
}
430+
431+
STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_contains_obj, set_contains);
432+
426433
/******************************************************************************/
427434
/* set constructors & public C API */
428435

@@ -445,6 +452,7 @@ STATIC const mp_map_elem_t set_locals_dict_table[] = {
445452
{ MP_OBJ_NEW_QSTR(MP_QSTR_symmetric_difference_update), (mp_obj_t)&set_symmetric_difference_update_obj },
446453
{ MP_OBJ_NEW_QSTR(MP_QSTR_union), (mp_obj_t)&set_union_obj },
447454
{ MP_OBJ_NEW_QSTR(MP_QSTR_update), (mp_obj_t)&set_update_obj },
455+
{ MP_OBJ_NEW_QSTR(MP_QSTR___contains__), (mp_obj_t)&set_contains_obj },
448456
};
449457

450458
STATIC MP_DEFINE_CONST_DICT(set_locals_dict, set_locals_dict_table);

py/qstrdefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Q(__path__)
1717
Q(__repl_print__)
1818

1919
Q(__bool__)
20+
Q(__contains__)
2021
Q(__enter__)
2122
Q(__exit__)
2223
Q(__len__)

0 commit comments

Comments
 (0)