Skip to content

Commit cc57bd2

Browse files
committed
mp_obj_equal(): For non-trivial types, call out to type's special method.
1 parent 729e9cc commit cc57bd2

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

py/obj.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
117117
} else if (MP_OBJ_IS_TYPE(o1, &str_type) && MP_OBJ_IS_TYPE(o2, &str_type)) {
118118
return mp_obj_str_get(o1) == mp_obj_str_get(o2);
119119
} else {
120+
mp_obj_base_t *o = o1;
121+
if (o->type->binary_op != NULL) {
122+
mp_obj_t r = o->type->binary_op(RT_COMPARE_OP_EQUAL, o1, o2);
123+
if (r != MP_OBJ_NULL) {
124+
return r == mp_const_true ? true : false;
125+
}
126+
}
120127
// TODO: Debugging helper
121128
printf("Equality for '%s' and '%s' types not yet implemented\n", mp_obj_get_type_str(o1), mp_obj_get_type_str(o2));
122129
assert(0);

0 commit comments

Comments
 (0)