From 9ec1caf42e7733b5141b7aecf1b6e58834a94bf7 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 10 Feb 2020 21:41:22 +1100 Subject: py: Expand type equality flags to 3 separate ones, fix bool/namedtuple. Both bool and namedtuple will check against other types for equality; int, float and complex for bool, and tuple for namedtuple. So to make them work after the recent commit 3aab54bf434e7f025a91ea05052f1bac439fad8c they would need MP_TYPE_FLAG_NEEDS_FULL_EQ_TEST set. But that makes all bool and namedtuple equality checks less efficient because mp_obj_equal_not_equal() could no longer short-cut x==x, and would need to try __ne__. To improve this, this commit splits the MP_TYPE_FLAG_NEEDS_FULL_EQ_TEST flags into 3 separate flags to give types more fine-grained control over how their equality behaves. These new flags are then used to fix bool and namedtuple equality. Fixes issue #5615 and #5620. --- 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 6181d5f57..347f692a4 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -185,8 +185,8 @@ STATIC mp_obj_t float_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs const mp_obj_type_t mp_type_float = { { &mp_type_type }, + .flags = MP_TYPE_FLAG_EQ_NOT_REFLEXIVE | MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE, .name = MP_QSTR_float, - .flags = MP_TYPE_FLAG_NEEDS_FULL_EQ_TEST, .print = float_print, .make_new = float_make_new, .unary_op = float_unary_op, -- cgit v1.2.3