summaryrefslogtreecommitdiff
path: root/py/runtime.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-01-27 18:02:25 +0000
committerDamien George <damien.p.george@gmail.com>2015-01-27 18:02:25 +0000
commita5efcd474563ed4e3d979a619f073abab8379a09 (patch)
tree89ec313adc7023552dbb09ad92e0ba9ff00082ef /py/runtime.c
parenta9dc9b8f6dc29d842f0a7427cc3cf068ae1cfbea (diff)
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.
Diffstat (limited to 'py/runtime.c')
-rw-r--r--py/runtime.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/py/runtime.c b/py/runtime.c
index 3597f5654..fc8d128e7 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -242,10 +242,9 @@ mp_obj_t mp_unary_op(mp_uint_t op, mp_obj_t arg) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
"unsupported type for operator"));
} else {
- // TODO specify in error message what the operator is
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
- "bad operand type for unary operator: '%s'",
- mp_obj_get_type_str(arg)));
+ "unsupported type for %s: '%s'",
+ qstr_str(mp_unary_op_method_name[op]), mp_obj_get_type_str(arg)));
}
}
}
@@ -537,10 +536,9 @@ unsupported_op:
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
"unsupported type for operator"));
} else {
- // TODO specify in error message what the operator is
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
- "unsupported operand types for binary operator: '%s', '%s'",
- mp_obj_get_type_str(lhs), mp_obj_get_type_str(rhs)));
+ "unsupported types for %s: '%s', '%s'",
+ qstr_str(mp_binary_op_method_name[op]), mp_obj_get_type_str(lhs), mp_obj_get_type_str(rhs)));
}
zero_division: