mirror of
https://github.com/micropython/micropython.git
synced 2026-01-07 04:30:24 +01:00
all: Use MP_ERROR_TEXT for all error messages.
This commit is contained in:
committed by
Damien George
parent
85858e72df
commit
def76fe4d9
30
py/objtype.c
30
py/objtype.c
@@ -349,10 +349,10 @@ mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, size
|
||||
}
|
||||
if (init_ret != mp_const_none) {
|
||||
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||
mp_raise_TypeError("__init__() should return None");
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("__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));
|
||||
MP_ERROR_TEXT("__init__() should return None, not '%s'"), mp_obj_get_type_str(init_ret));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -627,7 +627,7 @@ STATIC void mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *des
|
||||
// the code.
|
||||
const mp_obj_t *proxy = mp_obj_property_get(member);
|
||||
if (proxy[0] == mp_const_none) {
|
||||
mp_raise_msg(&mp_type_AttributeError, "unreadable attribute");
|
||||
mp_raise_msg(&mp_type_AttributeError, MP_ERROR_TEXT("unreadable attribute"));
|
||||
} else {
|
||||
dest[0] = mp_call_function_n_kw(proxy[0], 1, 0, &self_in);
|
||||
}
|
||||
@@ -864,10 +864,10 @@ mp_obj_t mp_obj_instance_call(mp_obj_t self_in, size_t n_args, size_t n_kw, cons
|
||||
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");
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("object not callable"));
|
||||
#else
|
||||
mp_raise_msg_varg(&mp_type_TypeError,
|
||||
"'%s' object isn't callable", mp_obj_get_type_str(self_in));
|
||||
MP_ERROR_TEXT("'%s' object isn't callable"), mp_obj_get_type_str(self_in));
|
||||
#endif
|
||||
}
|
||||
mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
@@ -978,7 +978,7 @@ STATIC mp_obj_t type_make_new(const mp_obj_type_t *type_in, size_t n_args, size_
|
||||
return mp_obj_new_type(mp_obj_str_get_qstr(args[0]), args[1], args[2]);
|
||||
|
||||
default:
|
||||
mp_raise_TypeError("type takes 1 or 3 arguments");
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("type takes 1 or 3 arguments"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -989,9 +989,9 @@ STATIC mp_obj_t type_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp
|
||||
|
||||
if (self->make_new == NULL) {
|
||||
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
|
||||
mp_raise_TypeError("cannot create instance");
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("cannot create instance"));
|
||||
#else
|
||||
mp_raise_msg_varg(&mp_type_TypeError, "cannot create '%q' instances", self->name);
|
||||
mp_raise_msg_varg(&mp_type_TypeError, MP_ERROR_TEXT("cannot create '%q' instances"), self->name);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1060,7 +1060,7 @@ STATIC void type_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||
if (check_for_special_accessors(MP_OBJ_NEW_QSTR(attr), dest[1])) {
|
||||
if (self->flags & MP_TYPE_FLAG_IS_SUBCLASSED) {
|
||||
// This class is already subclassed so can't have special accessors added
|
||||
mp_raise_msg(&mp_type_AttributeError, "can't add special method to already-subclassed class");
|
||||
mp_raise_msg(&mp_type_AttributeError, MP_ERROR_TEXT("can't add special method to already-subclassed class"));
|
||||
}
|
||||
self->flags |= MP_TYPE_FLAG_HAS_SPECIAL_ACCESSORS;
|
||||
}
|
||||
@@ -1111,10 +1111,10 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
|
||||
// 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");
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("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);
|
||||
MP_ERROR_TEXT("type '%q' isn't an acceptable base type"), t->name);
|
||||
#endif
|
||||
}
|
||||
#if ENABLE_SPECIAL_ACCESSORS
|
||||
@@ -1151,7 +1151,7 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
|
||||
#if MICROPY_MULTIPLE_INHERITANCE
|
||||
o->parent = MP_OBJ_TO_PTR(bases_tuple);
|
||||
#else
|
||||
mp_raise_NotImplementedError("multiple inheritance not supported");
|
||||
mp_raise_NotImplementedError(MP_ERROR_TEXT("multiple inheritance not supported"));
|
||||
#endif
|
||||
} else {
|
||||
o->parent = MP_OBJ_TO_PTR(bases_items[0]);
|
||||
@@ -1178,7 +1178,7 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
|
||||
const mp_obj_type_t *native_base;
|
||||
size_t num_native_bases = instance_count_native_bases(o, &native_base);
|
||||
if (num_native_bases > 1) {
|
||||
mp_raise_TypeError("multiple bases have instance lay-out conflict");
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("multiple bases have instance lay-out conflict"));
|
||||
}
|
||||
|
||||
mp_map_t *locals_map = &o->locals_dict->map;
|
||||
@@ -1361,7 +1361,7 @@ STATIC mp_obj_t mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo) {
|
||||
} else if (mp_obj_is_type(classinfo, &mp_type_tuple)) {
|
||||
mp_obj_tuple_get(classinfo, &len, &items);
|
||||
} else {
|
||||
mp_raise_TypeError("issubclass() arg 2 must be a class or a tuple of classes");
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("issubclass() arg 2 must be a class or a tuple of classes"));
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
@@ -1375,7 +1375,7 @@ STATIC mp_obj_t mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo) {
|
||||
|
||||
STATIC mp_obj_t mp_builtin_issubclass(mp_obj_t object, mp_obj_t classinfo) {
|
||||
if (!mp_obj_is_type(object, &mp_type_type)) {
|
||||
mp_raise_TypeError("issubclass() arg 1 must be a class");
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("issubclass() arg 1 must be a class"));
|
||||
}
|
||||
return mp_obj_is_subclass(object, classinfo);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user