py: Change MP_UNARY_OP_INT to MP_UNARY_OP_INT_MAYBE.

To be consistent with MP_UNARY_OP_INT_FLOAT and MP_UNARY_OP_INT_COMPLEX,
and allow int() to first check if a type supports __int__ before trying
other things (as per CPython).

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2023-05-25 10:57:08 +10:00
parent 3ae78e803b
commit 48ffd6596e
11 changed files with 50 additions and 39 deletions

View File

@@ -119,6 +119,8 @@ mp_obj_t mp_obj_int_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
self->val = -self->val;
return MP_OBJ_FROM_PTR(self);
}
case MP_UNARY_OP_INT_MAYBE:
return o_in;
default:
return MP_OBJ_NULL; // op not supported
}