Implement __bool__ and __len__ via unary_op virtual method for all types.
__bool__() and __len__() are just the same as __neg__() or __invert__(), and require efficient dispatching implementation (not requiring search/lookup). type->unary_op() is just the right choice for this short of adding standalone virtual method(s) to already big mp_obj_type_t structure.
This commit is contained in:
@@ -18,7 +18,7 @@ static void none_print(void (*print)(void *env, const char *fmt, ...), void *env
|
||||
|
||||
static mp_obj_t none_unary_op(int op, mp_obj_t o_in) {
|
||||
switch (op) {
|
||||
case RT_UNARY_OP_NOT: return mp_const_true;
|
||||
case RT_UNARY_OP_BOOL: return mp_const_false;
|
||||
default: return MP_OBJ_NULL; // op not supported for None
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user