10000 py/objint: Make length argument optional in int.to_bytes() method. · projectgus/micropython@0b432b3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0b432b3

Browse files
AmirHmZzdpgeorge
authored andcommitted
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>
1 parent 80c5e76 commit 0b432b3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

py/objint.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ static mp_obj_t int_to_bytes(size_t n_args, const mp_obj_t *args) {
424424
// TODO: Support signed (currently behaves as if signed=(val < 0))
425425
bool overflow;
426426

427-
mp_int_t dlen = mp_obj_get_int(args[1]);
427+
mp_int_t dlen = n_args < 2 ? 1 : mp_obj_get_int(args[1]);
428428
if (dlen < 0) {
429429
mp_raise_ValueError(NULL);
430430
}
@@ -468,7 +468,7 @@ static mp_obj_t int_to_bytes(size_t n_args, const mp_obj_t *args) {
468468

469469
return mp_obj_new_bytes_from_vstr(&vstr);
470470
}
471-
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(int_to_bytes_obj, 2, 4, int_to_bytes);
471+
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(int_to_bytes_obj, 1, 4, int_to_bytes);
472472

473473
static const mp_rom_map_elem_t int_locals_dict_table[] = {
474474
{ MP_ROM_QSTR(MP_QSTR_from_bytes), MP_ROM_PTR(&int_from_bytes_obj) },

0 commit comments

Comments
 (0)
0