Skip to content

Commit 80c5e76

Browse files
AmirHmZzdpgeorge
authored andcommitted
py/objint: Make byteorder 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 9670666 commit 80c5e76

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

py/objint.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,14 +422,13 @@ static MP_DEFINE_CONST_CLASSMETHOD_OBJ(int_from_bytes_obj, MP_ROM_PTR(&int_from_
422422

423423
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))
425-
(void)n_args;
426425
bool overflow;
427426

428427
mp_int_t dlen = mp_obj_get_int(args[1]);
429428
if (dlen < 0) {
430429
mp_raise_ValueError(NULL);
431430
}
432-
bool big_endian = args[2] != MP_OBJ_NEW_QSTR(MP_QSTR_little);
431+
bool big_endian = n_args < 3 || args[2] != MP_OBJ_NEW_QSTR(MP_QSTR_little);
433432

434433
vstr_t vstr;
435434
vstr_init_len(&vstr, dlen);
@@ -469,7 +468,7 @@ static mp_obj_t int_to_bytes(size_t n_args, const mp_obj_t *args) {
469468

470469
return mp_obj_new_bytes_from_vstr(&vstr);
471470
}
472-
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(int_to_bytes_obj, 3, 4, int_to_bytes);
471+
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(int_to_bytes_obj, 2, 4, int_to_bytes);
473472

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy