all: Convert exceptions to use mp_raise_XXX helpers in remaining places.
This commit is contained in:
parent
8f0778b209
commit
ad9a0ec8ab
|
@ -45,7 +45,7 @@ typedef struct _mp_obj_vfs_posix_file_t {
|
|||
#ifdef MICROPY_CPYTHON_COMPAT
|
||||
STATIC void check_fd_is_open(const mp_obj_vfs_posix_file_t *o) {
|
||||
if (o->fd < 0) {
|
||||
mp_raise_msg(&mp_type_ValueError, "I/O operation on closed file");
|
||||
mp_raise_ValueError("I/O operation on closed file");
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
|
|
@ -74,7 +74,7 @@ STATIC mp_obj_t esp32_wake_on_ext0(size_t n_args, const mp_obj_t *pos_args, mp_m
|
|||
gpio_num_t pin_id = machine_pin_get_id(args[ARG_pin].u_obj);
|
||||
if (pin_id != machine_rtc_config.ext0_pin) {
|
||||
if (!RTC_IS_VALID_EXT_PIN(pin_id)) {
|
||||
mp_raise_msg(&mp_type_ValueError, "invalid pin");
|
||||
mp_raise_ValueError("invalid pin");
|
||||
}
|
||||
machine_rtc_config.ext0_pin = pin_id;
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ STATIC mp_obj_t esp32_wake_on_ext1(size_t n_args, const mp_obj_t *pos_args, mp_m
|
|||
|
||||
gpio_num_t pin_id = machine_pin_get_id(elem[i]);
|
||||
if (!RTC_IS_VALID_EXT_PIN(pin_id)) {
|
||||
mp_raise_msg(&mp_type_ValueError, "invalid pin");
|
||||
mp_raise_ValueError("invalid pin");
|
||||
break;
|
||||
}
|
||||
ext1_pins |= (1ll << pin_id);
|
||||
|
|
|
@ -191,7 +191,7 @@ STATIC mp_obj_t ppp_connect_py(size_t n_args, const mp_obj_t *args, mp_map_t *kw
|
|||
case PPPAUTHTYPE_CHAP:
|
||||
break;
|
||||
default:
|
||||
mp_raise_msg(&mp_type_ValueError, "invalid auth");
|
||||
mp_raise_ValueError("invalid auth");
|
||||
}
|
||||
|
||||
if (parsed_args[ARG_authmode].u_int != PPPAUTHTYPE_NONE) {
|
||||
|
|
|
@ -227,7 +227,7 @@ STATIC mp_obj_t microbit_image_make_new(const mp_obj_type_t *type_in, mp_uint_t
|
|||
return image_from_parsed_str(str, len);
|
||||
}
|
||||
} else {
|
||||
mp_raise_msg(&mp_type_TypeError, "Image(s) takes a string.");
|
||||
mp_raise_TypeError("Image(s) takes a string.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -258,7 +258,7 @@ STATIC mp_obj_t microbit_image_make_new(const mp_obj_type_t *type_in, mp_uint_t
|
|||
}
|
||||
|
||||
default: {
|
||||
mp_raise_msg(&mp_type_TypeError, "Image() takes 0 to 3 arguments");
|
||||
mp_raise_TypeError("Image() takes 0 to 3 arguments");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -363,7 +363,7 @@ MP_DEFINE_CONST_FUN_OBJ_3(microbit_image_get_pixel_obj, microbit_image_get_pixel
|
|||
/* Raise an exception if not mutable */
|
||||
static void check_mutability(microbit_image_obj_t *self) {
|
||||
if (self->base.five) {
|
||||
mp_raise_msg(&mp_type_TypeError, "image cannot be modified (try copying first)");
|
||||
mp_raise_TypeError("image cannot be modified (try copying first)");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -406,10 +406,10 @@ mp_obj_t microbit_image_blit(mp_uint_t n_args, const mp_obj_t *args) {
|
|||
|
||||
mp_obj_t src = args[1];
|
||||
if (mp_obj_get_type(src) != µbit_image_type) {
|
||||
mp_raise_msg(&mp_type_TypeError, "expecting an image");
|
||||
mp_raise_TypeError("expecting an image");
|
||||
}
|
||||
if (n_args == 7) {
|
||||
mp_raise_msg(&mp_type_TypeError, "must specify both offsets");
|
||||
mp_raise_TypeError("must specify both offsets");
|
||||
}
|
||||
mp_int_t x = mp_obj_get_int(args[2]);
|
||||
mp_int_t y = mp_obj_get_int(args[3]);
|
||||
|
|
|
@ -387,7 +387,7 @@ STATIC mp_obj_t mp_builtin_pow(size_t n_args, const mp_obj_t *args) {
|
|||
return mp_binary_op(MP_BINARY_OP_POWER, args[0], args[1]);
|
||||
default:
|
||||
#if !MICROPY_PY_BUILTINS_POW3
|
||||
mp_raise_msg(&mp_type_NotImplementedError, "3-arg pow() not supported");
|
||||
mp_raise_NotImplementedError("3-arg pow() not supported");
|
||||
#elif MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_MPZ
|
||||
return mp_binary_op(MP_BINARY_OP_MODULO, mp_binary_op(MP_BINARY_OP_POWER, args[0], args[1]), args[2]);
|
||||
#else
|
||||
|
|
|
@ -294,7 +294,7 @@ STATIC mp_obj_t mp_math_factorial_inner(mp_uint_t start, mp_uint_t end) {
|
|||
STATIC mp_obj_t mp_math_factorial(mp_obj_t x_obj) {
|
||||
mp_int_t max = mp_obj_get_int(x_obj);
|
||||
if (max < 0) {
|
||||
mp_raise_msg(&mp_type_ValueError, "negative factorial");
|
||||
mp_raise_ValueError("negative factorial");
|
||||
} else if (max == 0) {
|
||||
return MP_OBJ_NEW_SMALL_INT(1);
|
||||
}
|
||||
|
@ -308,7 +308,7 @@ STATIC mp_obj_t mp_math_factorial(mp_obj_t x_obj) {
|
|||
STATIC mp_obj_t mp_math_factorial(mp_obj_t x_obj) {
|
||||
mp_int_t max = mp_obj_get_int(x_obj);
|
||||
if (max < 0) {
|
||||
mp_raise_msg(&mp_type_ValueError, "negative factorial");
|
||||
mp_raise_ValueError("negative factorial");
|
||||
} else if (max <= 1) {
|
||||
return MP_OBJ_NEW_SMALL_INT(1);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue