Commit 7e7940c3 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

py: Fix __len__ special method result handling.

Having both MP_OBJ_NOT_SUPPORTED and MP_OBJ_NULL is arguably confusing.
parent c48d6f7a
......@@ -357,7 +357,12 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) {
} else {
mp_obj_type_t *type = mp_obj_get_type(o_in);
if (type->unary_op != NULL) {
return type->unary_op(MP_UNARY_OP_LEN, o_in);
mp_obj_t val = type->unary_op(MP_UNARY_OP_LEN, o_in);
// TODO: Here's the case of having MP_OBJ_NOT_SUPPORTED is confusing
if (val == MP_OBJ_NOT_SUPPORTED) {
return MP_OBJ_NULL;
}
return val;
} else {
return MP_OBJ_NULL;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment