summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2023-06-01 12:12:22 +1000
committerDamien George <damien@micropython.org>2023-06-01 14:18:54 +1000
commit66dc1397c92f6accf102bcd15c6395902fd46c8b (patch)
treeb9743d03804279fa38222bc2b5edb6da2756ff5b /py
parent48ffd6596e7a4c185a81be233b46d3c99a83a7ac (diff)
py/obj: Accept user types in mp_obj_get_int_maybe.
This is possible now that MP_UNARY_OP_INT_MAYBE exists. As a consequence mp_obj_get_int now also supports user types, which was previously possible with MP_UNARY_OP_INT but no tests existed for it. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'py')
-rw-r--r--py/obj.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/py/obj.c b/py/obj.c
index dc6919467..64c52eeb7 100644
--- a/py/obj.c
+++ b/py/obj.c
@@ -326,7 +326,12 @@ bool mp_obj_get_int_maybe(mp_const_obj_t arg, mp_int_t *value) {
} else if (mp_obj_is_exact_type(arg, &mp_type_int)) {
*value = mp_obj_int_get_checked(arg);
} else {
- return false;
+ arg = mp_unary_op(MP_UNARY_OP_INT_MAYBE, (mp_obj_t)arg);
+ if (arg != MP_OBJ_NULL) {
+ *value = mp_obj_int_get_checked(arg);
+ } else {
+ return false;
+ }
}
return true;
}