diff options
| author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2018-08-29 17:59:36 +0300 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2018-12-07 17:28:04 +1100 |
| commit | b1d08726eeeadf0b91358cc8c46e156695b6a9c0 (patch) | |
| tree | a8d8235ef2738961eab0ca0c2da74e85ecef861d /py/obj.c | |
| parent | 113f00a9ab469a83d1004dac502077af0a8f4847 (diff) | |
py/obj: Add support for __int__ special method.
Based on the discussion, this special method is available unconditionally,
as converting to int is a common operation.
Diffstat (limited to 'py/obj.c')
| -rw-r--r-- | py/obj.c | 8 |
1 files changed, 2 insertions, 6 deletions
@@ -235,12 +235,8 @@ mp_int_t mp_obj_get_int(mp_const_obj_t arg) { } else if (MP_OBJ_IS_TYPE(arg, &mp_type_int)) { return mp_obj_int_get_checked(arg); } else { - if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { - mp_raise_TypeError("can't convert to int"); - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, - "can't convert %s to int", mp_obj_get_type_str(arg))); - } + mp_obj_t res = mp_unary_op(MP_UNARY_OP_INT, (mp_obj_t)arg); + return mp_obj_int_get_checked(res); } } |
