Skip to content

Commit 7e7940c

Browse files
committed
py: Fix __len__ special method result handling.
Having both MP_OBJ_NOT_SUPPORTED and MP_OBJ_NULL is arguably confusing.
1 parent c48d6f7 commit 7e7940c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

py/obj.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,12 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) {
357357
} else {
358358
mp_obj_type_t *type = mp_obj_get_type(o_in);
359359
if (type->unary_op != NULL) {
360-
return type->unary_op(MP_UNARY_OP_LEN, o_in);
360+
mp_obj_t val = type->unary_op(MP_UNARY_OP_LEN, o_in);
361+
// TODO: Here's the case of having MP_OBJ_NOT_SUPPORTED is confusing
362+
if (val == MP_OBJ_NOT_SUPPORTED) {
363+
return MP_OBJ_NULL;
364+
}
365+
return val;
361366
} else {
362367
return MP_OBJ_NULL;
363368
}

0 commit comments

Comments
 (0)