@ -277,7 +277,7 @@ mp_obj_t mp_unary_op(mp_unary_op_t op, mp_obj_t arg) {
case MP_UNARY_OP_HASH :
case MP_UNARY_OP_HASH :
return arg ;
return arg ;
case MP_UNARY_OP_POSITIVE :
case MP_UNARY_OP_POSITIVE :
case MP_UNARY_OP_INT :
case MP_UNARY_OP_INT_MAYBE :
return arg ;
return arg ;
case MP_UNARY_OP_NEGATIVE :
case MP_UNARY_OP_NEGATIVE :
// check for overflow
// check for overflow
@ -324,32 +324,23 @@ mp_obj_t mp_unary_op(mp_unary_op_t op, mp_obj_t arg) {
// if arg==mp_const_none.
// if arg==mp_const_none.
return mp_const_true ;
return mp_const_true ;
}
}
# if MICROPY_PY_BUILTINS_FLOAT
if ( op = = MP_UNARY_OP_INT_MAYBE
if ( op = = MP_UNARY_OP_FLOAT_MAYBE
# if MICROPY_PY_BUILTINS_FLOAT
| | op = = MP_UNARY_OP_FLOAT_MAYBE
# if MICROPY_PY_BUILTINS_COMPLEX
# if MICROPY_PY_BUILTINS_COMPLEX
| | op = = MP_UNARY_OP_COMPLEX_MAYBE
| | op = = MP_UNARY_OP_COMPLEX_MAYBE
# endif
# endif
# endif
) {
) {
// These operators may return MP_OBJ_NULL if they are not supported by the type.
return MP_OBJ_NULL ;
return MP_OBJ_NULL ;
}
}
# endif
// With MP_UNARY_OP_INT, mp_unary_op() becomes a fallback for mp_obj_get_int().
// In this case provide a more focused error message to not confuse, e.g. chr(1.0)
# if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE
# if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE
if ( op = = MP_UNARY_OP_INT ) {
mp_raise_TypeError ( MP_ERROR_TEXT ( " unsupported type for operator " ) ) ;
mp_raise_TypeError ( MP_ERROR_TEXT ( " can't convert to int " ) ) ;
} else {
mp_raise_TypeError ( MP_ERROR_TEXT ( " unsupported type for operator " ) ) ;
}
# else
# else
if ( op = = MP_UNARY_OP_INT ) {
mp_raise_msg_varg ( & mp_type_TypeError ,
mp_raise_msg_varg ( & mp_type_TypeError ,
MP_ERROR_TEXT ( " unsupported type for %q: '%s' " ) ,
MP_ERROR_TEXT ( " can't convert %s to int " ) , mp_obj_get_type_str ( arg ) ) ;
mp_unary_op_method_name [ op ] , mp_obj_get_type_str ( arg ) ) ;
} else {
mp_raise_msg_varg ( & mp_type_TypeError ,
MP_ERROR_TEXT ( " unsupported type for %q: '%s' " ) ,
mp_unary_op_method_name [ op ] , mp_obj_get_type_str ( arg ) ) ;
}
# endif
# endif
}
}
}
}
@ -1700,6 +1691,16 @@ NORETURN void mp_raise_StopIteration(mp_obj_t arg) {
}
}
}
}
NORETURN void mp_raise_TypeError_int_conversion ( mp_const_obj_t arg ) {
# if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE
( void ) arg ;
mp_raise_TypeError ( MP_ERROR_TEXT ( " can't convert to int " ) ) ;
# else
mp_raise_msg_varg ( & mp_type_TypeError ,
MP_ERROR_TEXT ( " can't convert %s to int " ) , mp_obj_get_type_str ( arg ) ) ;
# endif
}
NORETURN void mp_raise_OSError ( int errno_ ) {
NORETURN void mp_raise_OSError ( int errno_ ) {
mp_raise_type_arg ( & mp_type_OSError , MP_OBJ_NEW_SMALL_INT ( errno_ ) ) ;
mp_raise_type_arg ( & mp_type_OSError , MP_OBJ_NEW_SMALL_INT ( errno_ ) ) ;
}
}