Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions py/formatfloat.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
***********************************************************************/

#include <stdlib.h>
#include <stdint.h>

#include "mpconfig.h"

Expand Down
4 changes: 4 additions & 0 deletions py/obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ machine_int_t mp_obj_get_int(mp_obj_t arg) {
return MP_OBJ_SMALL_INT_VALUE(arg);
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_int)) {
return mp_obj_int_get_checked(arg);
#if MICROPY_ENABLE_FLOAT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This snippet was already there, was already discussed, and removed. Python is no flaky php and doesn't allow make glorious errors by using incorrect types for operations. E.g.:

>>> a=[1,2,4,4]
>>> a[1.0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: list indices must be integers, not float

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh.

Ok - I'll fix that up

} else if (MP_OBJ_IS_TYPE(arg, &mp_type_float)) {
return mp_obj_float_get(arg);
#endif
} else {
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "can't convert %s to int", mp_obj_get_type_str(arg)));
}
Expand Down
Loading