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.
diff --git a/py/objnone.c b/py/objnone.c
index 4151403..7af0b29 100644
--- a/py/objnone.c
+++ b/py/objnone.c
@@ -18,7 +18,7 @@
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
}
}