Skip to content

Commit ee01411

Browse files
committed
py: Add len(bytes).
1 parent 897fe0c commit ee01411

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

py/obj.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ uint mp_get_index(const mp_obj_type_t *type, machine_uint_t len, mp_obj_t index,
320320

321321
// may return MP_OBJ_NULL
322322
mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) {
323-
if (MP_OBJ_IS_STR(o_in)) {
323+
if (MP_OBJ_IS_STR(o_in) || MP_OBJ_IS_TYPE(o_in, &mp_type_bytes)) {
324324
return MP_OBJ_NEW_SMALL_INT((machine_int_t)mp_obj_str_get_len(o_in));
325325
} else {
326326
mp_obj_type_t *type = mp_obj_get_type(o_in);

py/objstr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,8 @@ uint mp_obj_str_get_hash(mp_obj_t self_in) {
14851485
}
14861486

14871487
uint mp_obj_str_get_len(mp_obj_t self_in) {
1488-
if (MP_OBJ_IS_STR(self_in)) {
1488+
// TODO This has a double check for the type, one in obj.c and one here
1489+
if (MP_OBJ_IS_STR(self_in) || MP_OBJ_IS_TYPE(self_in, &mp_type_bytes)) {
14891490
GET_STR_LEN(self_in, l);
14901491
return l;
14911492
} else {

0 commit comments

Comments
 (0)