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 3aab54bf43 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.
This commit is contained in:
Damien George
2020-02-10 21:41:22 +11:00
parent 0852acfc74
commit 9ec1caf42e
9 changed files with 20 additions and 14 deletions

View File

@@ -563,8 +563,8 @@ STATIC MP_DEFINE_CONST_DICT(frozenset_locals_dict, frozenset_locals_dict_table);
const mp_obj_type_t mp_type_frozenset = {
{ &mp_type_type },
.flags = MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE,
.name = MP_QSTR_frozenset,
.flags = MP_TYPE_FLAG_NEEDS_FULL_EQ_TEST,
.print = set_print,
.make_new = set_make_new,
.unary_op = set_unary_op,