py: Get rid of assert() in method argument checking functions.
Checks for number of args removes where guaranteed by function descriptor, self checking is replaced with mp_check_self(). In few cases, exception is raised instead of assert.
This commit is contained in:
19
py/objstr.c
19
py/objstr.c
@@ -412,7 +412,7 @@ STATIC mp_obj_t bytes_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
|
||||
}
|
||||
|
||||
STATIC mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) {
|
||||
assert(MP_OBJ_IS_STR_OR_BYTES(self_in));
|
||||
mp_check_self(MP_OBJ_IS_STR_OR_BYTES(self_in));
|
||||
const mp_obj_type_t *self_type = mp_obj_get_type(self_in);
|
||||
|
||||
// get separation string
|
||||
@@ -648,8 +648,7 @@ STATIC mp_obj_t str_rsplit(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
STATIC mp_obj_t str_finder(mp_uint_t n_args, const mp_obj_t *args, mp_int_t direction, bool is_index) {
|
||||
const mp_obj_type_t *self_type = mp_obj_get_type(args[0]);
|
||||
assert(2 <= n_args && n_args <= 4);
|
||||
assert(MP_OBJ_IS_STR_OR_BYTES(args[0]));
|
||||
mp_check_self(MP_OBJ_IS_STR_OR_BYTES(args[0]));
|
||||
|
||||
// check argument type
|
||||
if (mp_obj_get_type(args[1]) != self_type) {
|
||||
@@ -734,8 +733,7 @@ STATIC mp_obj_t str_endswith(size_t n_args, const mp_obj_t *args) {
|
||||
enum { LSTRIP, RSTRIP, STRIP };
|
||||
|
||||
STATIC mp_obj_t str_uni_strip(int type, mp_uint_t n_args, const mp_obj_t *args) {
|
||||
assert(1 <= n_args && n_args <= 2);
|
||||
assert(MP_OBJ_IS_STR_OR_BYTES(args[0]));
|
||||
mp_check_self(MP_OBJ_IS_STR_OR_BYTES(args[0]));
|
||||
const mp_obj_type_t *self_type = mp_obj_get_type(args[0]);
|
||||
|
||||
const byte *chars_to_del;
|
||||
@@ -1327,7 +1325,7 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
|
||||
}
|
||||
|
||||
mp_obj_t mp_obj_str_format(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
|
||||
assert(MP_OBJ_IS_STR_OR_BYTES(args[0]));
|
||||
mp_check_self(MP_OBJ_IS_STR_OR_BYTES(args[0]));
|
||||
|
||||
GET_STR_DATA_LEN(args[0], str, len);
|
||||
int arg_i = 0;
|
||||
@@ -1336,7 +1334,7 @@ mp_obj_t mp_obj_str_format(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
|
||||
}
|
||||
|
||||
STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_obj_t *args, mp_obj_t dict) {
|
||||
assert(MP_OBJ_IS_STR_OR_BYTES(pattern));
|
||||
mp_check_self(MP_OBJ_IS_STR_OR_BYTES(pattern));
|
||||
|
||||
GET_STR_DATA_LEN(pattern, str, len);
|
||||
const byte *start_str = str;
|
||||
@@ -1530,7 +1528,7 @@ not_enough_args:
|
||||
// The implementation is optimized, returning the original string if there's
|
||||
// nothing to replace.
|
||||
STATIC mp_obj_t str_replace(size_t n_args, const mp_obj_t *args) {
|
||||
assert(MP_OBJ_IS_STR_OR_BYTES(args[0]));
|
||||
mp_check_self(MP_OBJ_IS_STR_OR_BYTES(args[0]));
|
||||
|
||||
mp_int_t max_rep = -1;
|
||||
if (n_args == 4) {
|
||||
@@ -1636,8 +1634,7 @@ STATIC mp_obj_t str_replace(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
STATIC mp_obj_t str_count(size_t n_args, const mp_obj_t *args) {
|
||||
const mp_obj_type_t *self_type = mp_obj_get_type(args[0]);
|
||||
assert(2 <= n_args && n_args <= 4);
|
||||
assert(MP_OBJ_IS_STR_OR_BYTES(args[0]));
|
||||
mp_check_self(MP_OBJ_IS_STR_OR_BYTES(args[0]));
|
||||
|
||||
// check argument type
|
||||
if (mp_obj_get_type(args[1]) != self_type) {
|
||||
@@ -1677,7 +1674,7 @@ STATIC mp_obj_t str_count(size_t n_args, const mp_obj_t *args) {
|
||||
|
||||
#if MICROPY_PY_BUILTINS_STR_PARTITION
|
||||
STATIC mp_obj_t str_partitioner(mp_obj_t self_in, mp_obj_t arg, mp_int_t direction) {
|
||||
assert(MP_OBJ_IS_STR_OR_BYTES(self_in));
|
||||
mp_check_self(MP_OBJ_IS_STR_OR_BYTES(self_in));
|
||||
mp_obj_type_t *self_type = mp_obj_get_type(self_in);
|
||||
if (self_type != mp_obj_get_type(arg)) {
|
||||
bad_implicit_conversion(arg);
|
||||
|
||||
Reference in New Issue
Block a user