@@ -177,7 +177,12 @@ mp_int_t mp_obj_hash(mp_obj_t o_in) {
177177 // TODO delegate to __hash__ method if it exists
178178
179179 } else {
180- nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError , "unhashable type: '%s'" , mp_obj_get_type_str (o_in )));
180+ if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
181+ nlr_raise (mp_obj_new_exception_msg (& mp_type_TypeError , "unhashable type" ));
182+ } else {
183+ nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError ,
184+ "unhashable type: '%s'" , mp_obj_get_type_str (o_in )));
185+ }
181186 }
182187}
183188
@@ -230,9 +235,14 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
230235 }
231236 }
232237
233- nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_NotImplementedError ,
234- "Equality for '%s' and '%s' types not yet implemented" , mp_obj_get_type_str (o1 ), mp_obj_get_type_str (o2 )));
235- return false;
238+ if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
239+ nlr_raise (mp_obj_new_exception_msg (& mp_type_NotImplementedError ,
240+ "equality for given types not yet implemented" ));
241+ } else {
242+ nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_NotImplementedError ,
243+ "equality for '%s' and '%s' types not yet implemented" ,
244+ mp_obj_get_type_str (o1 ), mp_obj_get_type_str (o2 )));
245+ }
236246}
237247
238248mp_int_t mp_obj_get_int (mp_const_obj_t arg ) {
@@ -248,7 +258,13 @@ mp_int_t mp_obj_get_int(mp_const_obj_t arg) {
248258 } else if (MP_OBJ_IS_TYPE (arg , & mp_type_int )) {
249259 return mp_obj_int_get_checked (arg );
250260 } else {
251- nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError , "can't convert %s to int" , mp_obj_get_type_str (arg )));
261+ if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
262+ nlr_raise (mp_obj_new_exception_msg (& mp_type_TypeError ,
263+ "can't convert to int" ));
264+ } else {
265+ nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError ,
266+ "can't convert %s to int" , mp_obj_get_type_str (arg )));
267+ }
252268 }
253269}
254270
@@ -283,7 +299,13 @@ mp_float_t mp_obj_get_float(mp_obj_t arg) {
283299 } else if (MP_OBJ_IS_TYPE (arg , & mp_type_float )) {
284300 return mp_obj_float_get (arg );
285301 } else {
286- nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError , "can't convert %s to float" , mp_obj_get_type_str (arg )));
302+ if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
303+ nlr_raise (mp_obj_new_exception_msg (& mp_type_TypeError ,
304+ "can't convert to float" ));
305+ } else {
306+ nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError ,
307+ "can't convert %s to float" , mp_obj_get_type_str (arg )));
308+ }
287309 }
288310}
289311
@@ -307,7 +329,13 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
307329 } else if (MP_OBJ_IS_TYPE (arg , & mp_type_complex )) {
308330 mp_obj_complex_get (arg , real , imag );
309331 } else {
310- nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError , "can't convert %s to complex" , mp_obj_get_type_str (arg )));
332+ if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
333+ nlr_raise (mp_obj_new_exception_msg (& mp_type_TypeError ,
334+ "can't convert to complex" ));
335+ } else {
336+ nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError ,
337+ "can't convert %s to complex" , mp_obj_get_type_str (arg )));
338+ }
311339 }
312340}
313341#endif
@@ -319,15 +347,27 @@ void mp_obj_get_array(mp_obj_t o, mp_uint_t *len, mp_obj_t **items) {
319347 } else if (MP_OBJ_IS_TYPE (o , & mp_type_list )) {
320348 mp_obj_list_get (o , len , items );
321349 } else {
322- nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError , "object '%s' is not a tuple or list" , mp_obj_get_type_str (o )));
350+ if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
351+ nlr_raise (mp_obj_new_exception_msg (& mp_type_TypeError ,
352+ "expected tuple/list" ));
353+ } else {
354+ nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError ,
355+ "object '%s' is not a tuple or list" , mp_obj_get_type_str (o )));
356+ }
323357 }
324358}
325359
326360void mp_obj_get_array_fixed_n (mp_obj_t o , mp_uint_t len , mp_obj_t * * items ) {
327361 mp_uint_t seq_len ;
328362 mp_obj_get_array (o , & seq_len , items );
329363 if (seq_len != len ) {
330- nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_ValueError , "requested length %d but object has length %d" , len , seq_len ));
364+ if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
365+ nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError ,
366+ "tuple/list has wrong length" ));
367+ } else {
368+ nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_ValueError ,
369+ "requested length %d but object has length %d" , len , seq_len ));
370+ }
331371 }
332372}
333373
@@ -337,7 +377,14 @@ mp_uint_t mp_get_index(const mp_obj_type_t *type, mp_uint_t len, mp_obj_t index,
337377 if (MP_OBJ_IS_SMALL_INT (index )) {
338378 i = MP_OBJ_SMALL_INT_VALUE (index );
339379 } else if (!mp_obj_get_int_maybe (index , & i )) {
340- nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError , "%s indices must be integers, not %s" , qstr_str (type -> name ), mp_obj_get_type_str (index )));
380+ if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
381+ nlr_raise (mp_obj_new_exception_msg (& mp_type_TypeError ,
382+ "indices must be integers" ));
383+ } else {
384+ nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError ,
385+ "%s indices must be integers, not %s" ,
386+ qstr_str (type -> name ), mp_obj_get_type_str (index )));
387+ }
341388 }
342389
343390 if (i < 0 ) {
@@ -351,7 +398,12 @@ mp_uint_t mp_get_index(const mp_obj_type_t *type, mp_uint_t len, mp_obj_t index,
351398 }
352399 } else {
353400 if (i < 0 || i >= len ) {
354- nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_IndexError , "%s index out of range" , qstr_str (type -> name )));
401+ if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
402+ nlr_raise (mp_obj_new_exception_msg (& mp_type_IndexError , "index out of range" ));
403+ } else {
404+ nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_IndexError ,
405+ "%s index out of range" , qstr_str (type -> name )));
406+ }
355407 }
356408 }
357409 return i ;
@@ -379,7 +431,13 @@ mp_obj_t mp_obj_id(mp_obj_t o_in) {
379431mp_obj_t mp_obj_len (mp_obj_t o_in ) {
380432 mp_obj_t len = mp_obj_len_maybe (o_in );
381433 if (len == MP_OBJ_NULL ) {
382- nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError , "object of type '%s' has no len()" , mp_obj_get_type_str (o_in )));
434+ if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
435+ nlr_raise (mp_obj_new_exception_msg (& mp_type_TypeError ,
436+ "object has no len" ));
437+ } else {
438+ nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError ,
439+ "object of type '%s' has no len()" , mp_obj_get_type_str (o_in )));
440+ }
383441 } else {
384442 return len ;
385443 }
@@ -414,11 +472,29 @@ mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
414472 // TODO: call base classes here?
415473 }
416474 if (value == MP_OBJ_NULL ) {
417- nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError , "'%s' object does not support item deletion" , mp_obj_get_type_str (base )));
475+ if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
476+ nlr_raise (mp_obj_new_exception_msg (& mp_type_TypeError ,
477+ "object does not support item deletion" ));
478+ } else {
479+ nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError ,
480+ "'%s' object does not support item deletion" , mp_obj_get_type_str (base )));
481+ }
418482 } else if (value == MP_OBJ_SENTINEL ) {
419- nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError , "'%s' object is not subscriptable" , mp_obj_get_type_str (base )));
483+ if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
484+ nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError ,
485+ "object is not subscriptable" ));
486+ } else {
487+ nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError ,
488+ "'%s' object is not subscriptable" , mp_obj_get_type_str (base )));
489+ }
420490 } else {
421- nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError , "'%s' object does not support item assignment" , mp_obj_get_type_str (base )));
491+ if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
492+ nlr_raise (mp_obj_new_exception_msg (& mp_type_TypeError ,
493+ "object does not support item assignment" ));
494+ } else {
495+ nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError ,
496+ "'%s' object does not support item assignment" , mp_obj_get_type_str (base )));
497+ }
422498 }
423499}
424500
0 commit comments