use validate_int_range(). remove string translation entry

This commit is contained in:
foamyguy 2022-06-23 07:28:04 -05:00
parent 692492f83f
commit a45de19731
2 changed files with 3 additions and 13 deletions

View File

@ -3687,10 +3687,6 @@ msgstr ""
msgid "palette must be 32 bytes long" msgid "palette must be 32 bytes long"
msgstr "" msgstr ""
#: shared-bindings/displayio/Palette.c
msgid "palette_index out of bounds"
msgstr ""
#: shared-bindings/displayio/Palette.c #: shared-bindings/displayio/Palette.c
msgid "palette_index should be an int" msgid "palette_index should be an int"
msgstr "" msgstr ""

View File

@ -160,9 +160,7 @@ STATIC mp_obj_t displayio_palette_obj_make_transparent(mp_obj_t self_in, mp_obj_
if (!mp_obj_get_int_maybe(palette_index_obj, &palette_index)) { if (!mp_obj_get_int_maybe(palette_index_obj, &palette_index)) {
mp_raise_ValueError(translate("palette_index should be an int")); mp_raise_ValueError(translate("palette_index should be an int"));
} }
if (palette_index < 0 || (unsigned)palette_index >= common_hal_displayio_palette_get_len(self)) { palette_index = mp_arg_validate_int_range(palette_index, 0, common_hal_displayio_palette_get_len(self) - 1, MP_QSTR_palette_index);
mp_raise_IndexError(translate("palette_index out of bounds"));
}
common_hal_displayio_palette_make_transparent(self, palette_index); common_hal_displayio_palette_make_transparent(self, palette_index);
return mp_const_none; return mp_const_none;
@ -179,9 +177,7 @@ STATIC mp_obj_t displayio_palette_obj_make_opaque(mp_obj_t self_in, mp_obj_t pal
if (!mp_obj_get_int_maybe(palette_index_obj, &palette_index)) { if (!mp_obj_get_int_maybe(palette_index_obj, &palette_index)) {
mp_raise_ValueError(translate("palette_index should be an int")); mp_raise_ValueError(translate("palette_index should be an int"));
} }
if (palette_index < 0 || (unsigned)palette_index >= common_hal_displayio_palette_get_len(self)) { palette_index = mp_arg_validate_int_range(palette_index, 0, common_hal_displayio_palette_get_len(self) - 1, MP_QSTR_palette_index);
mp_raise_IndexError(translate("palette_index out of bounds"));
}
common_hal_displayio_palette_make_opaque(self, palette_index); common_hal_displayio_palette_make_opaque(self, palette_index);
return mp_const_none; return mp_const_none;
@ -199,9 +195,7 @@ STATIC mp_obj_t displayio_palette_obj_is_transparent(mp_obj_t self_in, mp_obj_t
if (!mp_obj_get_int_maybe(palette_index_obj, &palette_index)) { if (!mp_obj_get_int_maybe(palette_index_obj, &palette_index)) {
mp_raise_ValueError(translate("palette_index should be an int")); mp_raise_ValueError(translate("palette_index should be an int"));
} }
if (palette_index < 0 || (unsigned)palette_index >= common_hal_displayio_palette_get_len(self)) { palette_index = mp_arg_validate_int_range(palette_index, 0, common_hal_displayio_palette_get_len(self) - 1, MP_QSTR_palette_index);
mp_raise_IndexError(translate("palette_index out of bounds"));
}
return mp_obj_new_bool(common_hal_displayio_palette_is_transparent(self, palette_index)); return mp_obj_new_bool(common_hal_displayio_palette_is_transparent(self, palette_index));
} }