diff --git a/py/objstr.c b/py/objstr.c index 006deee095..e8b2512a24 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -1995,7 +1995,7 @@ mp_obj_t mp_obj_bytes_hex(size_t n_args, const mp_obj_t *args, const mp_obj_type // Code below assumes non-zero buffer length when computing size with // separator, so handle the zero-length case here. if (bufinfo.len == 0) { - return mp_const_empty_bytes; + return make_empty_str_of_type(type); } vstr_t vstr; diff --git a/tests/basics/builtin_str_hex.py b/tests/basics/builtin_str_hex.py index 544406cfc5..f77fe7c4fa 100644 --- a/tests/basics/builtin_str_hex.py +++ b/tests/basics/builtin_str_hex.py @@ -3,6 +3,7 @@ if not hasattr(bytes, "fromhex"): raise SystemExit for x in ( + b"", b"\x00\x01\x02\x03\x04\x05\x06\x07", b"\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f", b"\x7f\x80\xff",