Skip to content

Commit 4d3ab4f

Browse files
committed
Added non-keyword args to allowed_args
1 parent ac9cb93 commit 4d3ab4f

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

locale/circuitpython.pot

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ msgstr ""
205205
msgid "%q, %q, and %q must all be the same length"
206206
msgstr ""
207207

208+
#: py/objint.c
209+
msgid "%q=%q"
210+
msgstr ""
211+
208212
#: ports/espressif/bindings/espidf/__init__.c ports/espressif/esp_error.c
209213
#, c-format
210214
msgid "%s error 0x%x"
@@ -2450,10 +2454,6 @@ msgstr ""
24502454
msgid "byteorder is not a string"
24512455
msgstr ""
24522456

2453-
#: py/objint.c
2454-
msgid "byteorder must be 'little' or 'big'"
2455-
msgstr ""
2456-
24572457
#: py/objarray.c
24582458
msgid "bytes length not a multiple of item size"
24592459
msgstr ""
@@ -2957,10 +2957,6 @@ msgstr ""
29572957
msgid "frequency is read-only for this board"
29582958
msgstr ""
29592959

2960-
#: py/objint.c
2961-
msgid "from_bytes() does not implement signed=True"
2962-
msgstr ""
2963-
29642960
#: py/objdeque.c
29652961
msgid "full"
29662962
msgstr ""

py/objint.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -483,28 +483,30 @@ MP_DEFINE_CONST_FUN_OBJ_1(int_bit_length_obj, int_bit_length);
483483
STATIC mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
484484
// TODO: Support signed param (assumes signed=False at the moment)
485485

486-
enum { ARG_signed };
486+
enum { ARG_bytes, ARG_byteorder, ARG_signed };
487487
static const mp_arg_t allowed_args[] = {
488-
{ MP_QSTR_signed, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
488+
{ MP_QSTR_bytes, MP_ARG_REQUIRED | MP_ARG_OBJ },
489+
{ MP_QSTR_byteorder, MP_ARG_REQUIRED | MP_ARG_OBJ },
490+
{ MP_QSTR_signed, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
489491
};
490492
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
491-
mp_arg_parse_all(n_args - 3, pos_args + 3, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
493+
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
492494

493495
if (args[ARG_signed].u_bool) {
494-
mp_raise_msg(&mp_type_NotImplementedError, MP_ERROR_TEXT("from_bytes() does not implement signed=True"));
496+
mp_raise_NotImplementedError_varg(MP_ERROR_TEXT("%q=%q"), MP_QSTR_signed, MP_QSTR_True);
495497
}
496498

497499
// get the buffer info
498500
mp_buffer_info_t bufinfo;
499-
mp_get_buffer_raise(pos_args[1], &bufinfo, MP_BUFFER_READ);
501+
mp_get_buffer_raise(args[ARG_bytes].u_obj, &bufinfo, MP_BUFFER_READ);
500502

501503
const byte *buf = (const byte *)bufinfo.buf;
502504
int delta = 1;
503-
if (pos_args[2] == MP_OBJ_NEW_QSTR(MP_QSTR_little)) {
505+
if (args[ARG_byteorder].u_obj == MP_OBJ_NEW_QSTR(MP_QSTR_little)) {
504506
buf += bufinfo.len - 1;
505507
delta = -1;
506-
} else if (pos_args[2] != MP_OBJ_NEW_QSTR(MP_QSTR_big)) {
507-
mp_raise_ValueError(MP_ERROR_TEXT("byteorder must be 'little' or 'big'"));
508+
} else if (args[ARG_byteorder].u_obj != MP_OBJ_NEW_QSTR(MP_QSTR_big)) {
509+
mp_arg_error_invalid(MP_QSTR_byteorder);
508510
}
509511

510512
mp_uint_t value = 0;
@@ -513,7 +515,7 @@ STATIC mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *pos_args, mp_map_t
513515
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
514516
if (value > (MP_SMALL_INT_MAX >> 8)) {
515517
// Result will overflow a small-int so construct a big-int
516-
return mp_obj_int_from_bytes_impl(pos_args[2] != MP_OBJ_NEW_QSTR(MP_QSTR_little), bufinfo.len, bufinfo.buf);
518+
return mp_obj_int_from_bytes_impl(args[ARG_byteorder].u_obj != MP_OBJ_NEW_QSTR(MP_QSTR_little), bufinfo.len, bufinfo.buf);
517519
}
518520
#endif
519521
value = (value << 8) | *buf;

0 commit comments

Comments
 (0)