py: Specify unary/binary op name in TypeError error message.

Eg, "() + 1" now tells you that __add__ is not supported for tuple and
int types (before it just said the generic "binary operator").  We reuse
the table of names for slot lookup because it would be a waste of code
space to store the pretty name for each operator.
This commit is contained in:
Damien George
2015-01-27 18:02:25 +00:00
parent a9dc9b8f6d
commit a5efcd4745
4 changed files with 10 additions and 10 deletions

View File

@@ -323,7 +323,7 @@ mp_obj_t instance_make_new(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, c
return o;
}
STATIC const qstr unary_op_method_name[] = {
const qstr mp_unary_op_method_name[] = {
[MP_UNARY_OP_BOOL] = MP_QSTR___bool__,
[MP_UNARY_OP_LEN] = MP_QSTR___len__,
//[MP_UNARY_OP_POSITIVE,
@@ -334,7 +334,7 @@ STATIC const qstr unary_op_method_name[] = {
STATIC mp_obj_t instance_unary_op(mp_uint_t op, mp_obj_t self_in) {
mp_obj_instance_t *self = self_in;
qstr op_name = unary_op_method_name[op];
qstr op_name = mp_unary_op_method_name[op];
/* Still try to lookup native slot
if (op_name == 0) {
return MP_OBJ_NULL;