Merge remote-tracking branch 'origin/main' into main

This commit is contained in:
Hosted Weblate 2021-07-01 04:50:54 +02:00
commit b6c8098671
No known key found for this signature in database
GPG Key ID: A3FAAA06E6569B4C
2 changed files with 7 additions and 4 deletions

View File

@ -195,6 +195,9 @@ STATIC mp_obj_t bytearray_make_new(const mp_obj_type_t *type_in, size_t n_args,
// no args: construct an empty bytearray
return MP_OBJ_FROM_PTR(array_new(BYTEARRAY_TYPECODE, 0));
} else if (mp_obj_is_int(args[0])) {
if (n_args > 1) {
mp_raise_TypeError(MP_ERROR_TEXT("wrong number of arguments"));
}
// 1 arg, an integer: construct a blank bytearray of that length
mp_uint_t len = mp_obj_get_int(args[0]);
mp_obj_array_t *o = array_new(BYTEARRAY_TYPECODE, len);

View File

@ -233,6 +233,10 @@ STATIC mp_obj_t bytes_make_new(const mp_obj_type_t *type_in, size_t n_args, cons
return MP_OBJ_FROM_PTR(o);
}
if (n_args > 1) {
goto wrong_args;
}
if (mp_obj_is_small_int(args[0])) {
mp_int_t len = MP_OBJ_SMALL_INT_VALUE(args[0]);
if (len < 0) {
@ -244,10 +248,6 @@ STATIC mp_obj_t bytes_make_new(const mp_obj_type_t *type_in, size_t n_args, cons
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
if (n_args > 1) {
goto wrong_args;
}
// check if __bytes__ exists, and if so delegate to it
mp_obj_t dest[2];
mp_load_method_maybe(args[0], MP_QSTR___bytes__, dest);