Skip to content

Commit f130ca1

Browse files
committed
py: Make bytes type hashable.
1 parent 73b7027 commit f130ca1

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
@@ -110,7 +110,7 @@ machine_int_t mp_obj_hash(mp_obj_t o_in) {
110110
return 1; // needs to hash to same as the integer 1, since True==1
111111
} else if (MP_OBJ_IS_SMALL_INT(o_in)) {
112112
return MP_OBJ_SMALL_INT_VALUE(o_in);
113-
} else if (MP_OBJ_IS_STR(o_in)) {
113+
} else if (MP_OBJ_IS_STR(o_in) || MP_OBJ_IS_TYPE(o_in, &mp_type_bytes)) {
114114
return mp_obj_str_get_hash(o_in);
115115
} else if (MP_OBJ_IS_TYPE(o_in, &mp_type_NoneType)) {
116116
return (machine_int_t)o_in;

py/objstr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1480,7 +1480,8 @@ STATIC void bad_implicit_conversion(mp_obj_t self_in) {
14801480
}
14811481

14821482
uint mp_obj_str_get_hash(mp_obj_t self_in) {
1483-
if (MP_OBJ_IS_STR(self_in)) {
1483+
// TODO: This has too big overhead for hash accessor
1484+
if (MP_OBJ_IS_STR(self_in) || MP_OBJ_IS_TYPE(self_in, &mp_type_bytes)) {
14841485
GET_STR_HASH(self_in, h);
14851486
return h;
14861487
} else {

0 commit comments

Comments
 (0)