From c1d9bbc3453454aceb28f51e72e4aeb8ef1c12eb Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 30 Jan 2014 04:37:19 +0200 Subject: 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. --- py/objfloat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'py/objfloat.c') diff --git a/py/objfloat.c b/py/objfloat.c index 69fd65e199..9caeaf7686 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -47,7 +47,7 @@ static mp_obj_t float_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m static mp_obj_t float_unary_op(int op, mp_obj_t o_in) { mp_obj_float_t *o = o_in; switch (op) { - case RT_UNARY_OP_NOT: if (o->value != 0) { return mp_const_true;} else { return mp_const_false; } + case RT_UNARY_OP_BOOL: return MP_BOOL(o->value != 0); case RT_UNARY_OP_POSITIVE: return o_in; case RT_UNARY_OP_NEGATIVE: return mp_obj_new_float(-o->value); default: return NULL; // op not supported -- cgit v1.2.3