diff --git a/py/objint.c b/py/objint.c index 7895f4f201ed..cc7a77451764 100644 --- a/py/objint.c +++ b/py/objint.c @@ -490,7 +490,8 @@ static mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *pos_args, mp_map_t enum { ARG_bytes, ARG_byteorder, ARG_signed }; static const mp_arg_t allowed_args[] = { { MP_QSTR_bytes, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = NULL} }, - { MP_QSTR_byteorder, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = NULL} }, + // CIRCUITPY-CHANGE: not required and given a default value. + { MP_QSTR_byteorder, MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_QSTR(MP_QSTR_big)} }, { MP_QSTR_signed, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; @@ -527,7 +528,8 @@ static mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *pos_args, mp_map_t return mp_obj_new_int_from_uint(value); } -static MP_DEFINE_CONST_FUN_OBJ_KW(int_from_bytes_fun_obj, 3, int_from_bytes); +// CIRCUITPY-CHANGE: only two required args. +static MP_DEFINE_CONST_FUN_OBJ_KW(int_from_bytes_fun_obj, 2, int_from_bytes); static MP_DEFINE_CONST_CLASSMETHOD_OBJ(int_from_bytes_obj, MP_ROM_PTR(&int_from_bytes_fun_obj)); // CIRCUITPY-CHANGE: supports signed @@ -535,7 +537,8 @@ static mp_obj_t int_to_bytes(size_t n_args, const mp_obj_t *pos_args, mp_map_t * enum { ARG_length, ARG_byteorder, ARG_signed }; static const mp_arg_t allowed_args[] = { { MP_QSTR_length, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} }, - { MP_QSTR_byteorder, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, + // CIRCUITPY-CHANGE: not required and given a default value. + { MP_QSTR_byteorder, MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_QSTR(MP_QSTR_big)} }, { MP_QSTR_signed, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; @@ -575,7 +578,8 @@ static mp_obj_t int_to_bytes(size_t n_args, const mp_obj_t *pos_args, mp_map_t * return mp_obj_new_bytes_from_vstr(&vstr); } -static MP_DEFINE_CONST_FUN_OBJ_KW(int_to_bytes_obj, 3, int_to_bytes); +// CIRCUITPY-CHANGE: only two required args. +static MP_DEFINE_CONST_FUN_OBJ_KW(int_to_bytes_obj, 2, int_to_bytes); static const mp_rom_map_elem_t int_locals_dict_table[] = { // CIRCUITPY-CHANGE diff --git a/tests/basics/int_bytes.py b/tests/basics/int_bytes.py index 3840aa8e4f00..1f620158ecef 100644 --- a/tests/basics/int_bytes.py +++ b/tests/basics/int_bytes.py @@ -43,3 +43,7 @@ (-256).to_bytes(2, "little", signed=False) except OverflowError: print("OverflowError") + +# byteorder arg can be omitted; default is "big" +print(int.from_bytes(b"\x01\0")) +print((100).to_bytes(10))