diff options
| author | Damien George | 2014-05-28 14:09:46 +0100 |
|---|---|---|
| committer | Damien George | 2014-05-28 14:09:46 +0100 |
| commit | 813ed3bda6818bd8dd15ee5e3c673a24321e740b (patch) | |
| tree | 1e1b72d0fd165576cb72cc618b353df27030cddd | |
| parent | 503d6110338ab2d79e6c0f8f591a0ca6397717de (diff) | |
py: Make int(<longint>) work by just returning the longint.
| -rw-r--r-- | py/objint.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/py/objint.c b/py/objint.c index 328fb11e8..7d6258b7d 100644 --- a/py/objint.c +++ b/py/objint.c @@ -53,7 +53,10 @@ STATIC mp_obj_t mp_obj_int_make_new(mp_obj_t type_in, uint n_args, uint n_kw, co return MP_OBJ_NEW_SMALL_INT(0); case 1: - if (MP_OBJ_IS_STR(args[0])) { + if (MP_OBJ_IS_INT(args[0])) { + // already an int (small or long), just return it + return args[0]; + } else if (MP_OBJ_IS_STR(args[0])) { // a string, parse it uint l; const char *s = mp_obj_str_get_data(args[0], &l); @@ -63,6 +66,7 @@ STATIC mp_obj_t mp_obj_int_make_new(mp_obj_t type_in, uint n_args, uint n_kw, co return MP_OBJ_NEW_SMALL_INT((machine_int_t)(MICROPY_FLOAT_C_FUN(trunc)(mp_obj_float_get(args[0])))); #endif } else { + // try to convert to small int (eg from bool) return MP_OBJ_NEW_SMALL_INT(mp_obj_get_int(args[0])); } |
