mirror of
https://github.com/micropython/micropython.git
synced 2025-09-01 07:20:40 +02:00
py: Use preprocessor to detect error reporting level (terse/detailed).
Instead of compiler-level if-logic. This is necessary to know what error strings are included in the build at the preprocessor stage, so that string compression can be implemented.
This commit is contained in:
committed by
Damien George
parent
312c699491
commit
a9a745e4b4
47
py/objtype.c
47
py/objtype.c
@@ -348,14 +348,13 @@ mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, size
|
||||
m_del(mp_obj_t, args2, 2 + n_args + 2 * n_kw);
|
||||
}
|
||||
if (init_ret != mp_const_none) {
|
||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||
mp_raise_TypeError("__init__() should return None");
|
||||
} else {
|
||||
mp_raise_msg_varg(&mp_type_TypeError,
|
||||
"__init__() should return None, not '%s'", mp_obj_get_type_str(init_ret));
|
||||
}
|
||||
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||
mp_raise_TypeError("__init__() should return None");
|
||||
#else
|
||||
mp_raise_msg_varg(&mp_type_TypeError,
|
||||
"__init__() should return None, not '%s'", mp_obj_get_type_str(init_ret));
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// If the type had a native base that was not explicitly initialised
|
||||
@@ -864,12 +863,12 @@ mp_obj_t mp_obj_instance_call(mp_obj_t self_in, size_t n_args, size_t n_kw, cons
|
||||
mp_obj_t member[2] = {MP_OBJ_NULL, MP_OBJ_NULL};
|
||||
mp_obj_t call = mp_obj_instance_get_call(self_in, member);
|
||||
if (call == MP_OBJ_NULL) {
|
||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||
mp_raise_TypeError("object not callable");
|
||||
} else {
|
||||
mp_raise_msg_varg(&mp_type_TypeError,
|
||||
"'%s' object isn't callable", mp_obj_get_type_str(self_in));
|
||||
}
|
||||
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||
mp_raise_TypeError("object not callable");
|
||||
#else
|
||||
mp_raise_msg_varg(&mp_type_TypeError,
|
||||
"'%s' object isn't callable", mp_obj_get_type_str(self_in));
|
||||
#endif
|
||||
}
|
||||
mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (call == MP_OBJ_SENTINEL) {
|
||||
@@ -989,11 +988,11 @@ STATIC mp_obj_t type_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp
|
||||
mp_obj_type_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
if (self->make_new == NULL) {
|
||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||
mp_raise_TypeError("cannot create instance");
|
||||
} else {
|
||||
mp_raise_msg_varg(&mp_type_TypeError, "cannot create '%q' instances", self->name);
|
||||
}
|
||||
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||
mp_raise_TypeError("cannot create instance");
|
||||
#else
|
||||
mp_raise_msg_varg(&mp_type_TypeError, "cannot create '%q' instances", self->name);
|
||||
#endif
|
||||
}
|
||||
|
||||
// make new instance
|
||||
@@ -1111,12 +1110,12 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
|
||||
mp_obj_type_t *t = MP_OBJ_TO_PTR(bases_items[i]);
|
||||
// TODO: Verify with CPy, tested on function type
|
||||
if (t->make_new == NULL) {
|
||||
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
|
||||
mp_raise_TypeError("type isn't an acceptable base type");
|
||||
} else {
|
||||
mp_raise_msg_varg(&mp_type_TypeError,
|
||||
"type '%q' isn't an acceptable base type", t->name);
|
||||
}
|
||||
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||
mp_raise_TypeError("type isn't an acceptable base type");
|
||||
#else
|
||||
mp_raise_msg_varg(&mp_type_TypeError,
|
||||
"type '%q' isn't an acceptable base type", t->name);
|
||||
#endif
|
||||
}
|
||||
#if ENABLE_SPECIAL_ACCESSORS
|
||||
if (mp_obj_is_instance_type(t)) {
|
||||
|
Reference in New Issue
Block a user