diff options
| author | Amirreza Hamzavi <amirrezahamzavi2000@gmail.com> | 2024-04-30 19:10:25 +0330 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2024-09-02 14:14:36 +1000 |
| commit | 0b432b330688647d2c6a5ecaef5e1f5ab703595d (patch) | |
| tree | 6d84dd9c0c3752efcf2c6cd3651c81244fb4ade0 /py/objint.c | |
| parent | 80c5e76483bd8e4d6730d04eabf1ee480ed36362 (diff) | |
py/objint: Make length argument optional in int.to_bytes() method.
This was made optional in CPython 3.11.
Signed-off-by: Amirreza Hamzavi <amirrezahamzavi2000@gmail.com>
Diffstat (limited to 'py/objint.c')
| -rw-r--r-- | py/objint.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/py/objint.c b/py/objint.c index 14de8bfee..a6aed8b8a 100644 --- a/py/objint.c +++ b/py/objint.c @@ -424,7 +424,7 @@ static mp_obj_t int_to_bytes(size_t n_args, const mp_obj_t *args) { // TODO: Support signed (currently behaves as if signed=(val < 0)) bool overflow; - mp_int_t dlen = mp_obj_get_int(args[1]); + mp_int_t dlen = n_args < 2 ? 1 : mp_obj_get_int(args[1]); if (dlen < 0) { mp_raise_ValueError(NULL); } @@ -468,7 +468,7 @@ static mp_obj_t int_to_bytes(size_t n_args, const mp_obj_t *args) { return mp_obj_new_bytes_from_vstr(&vstr); } -static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(int_to_bytes_obj, 2, 4, int_to_bytes); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(int_to_bytes_obj, 1, 4, int_to_bytes); static const mp_rom_map_elem_t int_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_from_bytes), MP_ROM_PTR(&int_from_bytes_obj) }, |
