Skip to content

Commit 813ed3b

Browse files
committed
py: Make int(<longint>) work by just returning the longint.
1 parent 503d611 commit 813ed3b

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

py/objint.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
5353
return MP_OBJ_NEW_SMALL_INT(0);
5454

5555
case 1:
56-
if (MP_OBJ_IS_STR(args[0])) {
56+
if (MP_OBJ_IS_INT(args[0])) {
57+
// already an int (small or long), just return it
58+
return args[0];
59+
} else if (MP_OBJ_IS_STR(args[0])) {
5760
// a string, parse it
5861
uint l;
5962
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
6366
return MP_OBJ_NEW_SMALL_INT((machine_int_t)(MICROPY_FLOAT_C_FUN(trunc)(mp_obj_float_get(args[0]))));
6467
#endif
6568
} else {
69+
// try to convert to small int (eg from bool)
6670
return MP_OBJ_NEW_SMALL_INT(mp_obj_get_int(args[0]));
6771
}
6872

0 commit comments

Comments
 (0)