diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-01-04 01:38:26 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-01-04 02:35:49 +0200 |
commit | f8b9d3c41addea79851c355f014db9f0f256cdaf (patch) | |
tree | 54f51c53b6259f17653a8d3d65391857da6722bd | |
parent | e606cb656165aff2424fb6ca45f09d606246d073 (diff) | |
download | micropython-f8b9d3c41addea79851c355f014db9f0f256cdaf.tar.gz micropython-f8b9d3c41addea79851c355f014db9f0f256cdaf.zip |
str: Throw TypeError for invalid index type and clean up comments.
-rw-r--r-- | py/objstr.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/py/objstr.c b/py/objstr.c index 8e3e9d9025..6a0721d45f 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -27,13 +27,11 @@ mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { const char *lhs_str = qstr_str(lhs->qstr); switch (op) { case RT_BINARY_OP_SUBSCR: - // string access - // XXX a massive hack! - // TODO: need predicate to check for int-like type (bools are such for example) // ["no", "yes"][1 == 2] is common idiom if (MP_OBJ_IS_SMALL_INT(rhs_in)) { // TODO: This implements byte string access for single index so far + // TODO: Handle negative indexes. return mp_obj_new_int(lhs_str[mp_obj_get_int(rhs_in)]); #if MICROPY_ENABLE_SLICE } else if (MP_OBJ_IS_TYPE(rhs_in, &slice_type)) { @@ -50,8 +48,9 @@ mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { return mp_obj_new_str(qstr_from_strn_copy(lhs_str + start, stop - start)); #endif } else { - // Throw TypeError here - assert(0); + // Message doesn't match CPython, but we don't have so much bytes as they + // to spend them on verbose wording + nlr_jump(mp_obj_new_exception_msg(rt_q_TypeError, "index must be int")); } case RT_BINARY_OP_ADD: |