summaryrefslogtreecommitdiff
path: root/py/objint.c
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2024-01-03 19:31:35 -0600
committerDamien George <damien@micropython.org>2025-01-26 22:54:58 +1100
commit13b13d1fdd05549d504eeded0b5aa8871d5e5dcf (patch)
tree0cd66eb9e2e2cb2ca0c6904c0093bf59ed77c1cb /py/objint.c
parent7b3f189b1723fe642f122a3b7826d16fe32f801a (diff)
py/parsenum: Throw an exception for invalid int literals like "01".
This includes making int("01") parse in base 10 like standard Python. When a base of 0 is specified it means auto-detect based on the prefix, and literals begining with 0 (except when the literal is all 0's) like "01" are then invalid and now throw an exception. The new error message is different from CPython. It says e.g., `SyntaxError: invalid syntax for integer with base 0: '09'` Additional test cases were added to cover the changed & added code. Co-authored-by: Damien George <damien@micropython.org> Signed-off-by: Jeff Epler <jepler@gmail.com>
Diffstat (limited to 'py/objint.c')
-rw-r--r--py/objint.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/py/objint.c b/py/objint.c
index 773e18034..4be6009a4 100644
--- a/py/objint.c
+++ b/py/objint.c
@@ -55,7 +55,7 @@ static mp_obj_t mp_obj_int_make_new(const mp_obj_type_t *type_in, size_t n_args,
return o;
} else if (mp_get_buffer(args[0], &bufinfo, MP_BUFFER_READ)) {
// a textual representation, parse it
- return mp_parse_num_integer(bufinfo.buf, bufinfo.len, 0, NULL);
+ return mp_parse_num_integer(bufinfo.buf, bufinfo.len, 10, NULL);
#if MICROPY_PY_BUILTINS_FLOAT
} else if (mp_obj_is_float(args[0])) {
return mp_obj_new_int_from_float(mp_obj_float_get(args[0]));