diff options
author | Damien George <damien.p.george@gmail.com> | 2020-02-10 21:41:22 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2020-02-11 11:06:00 +1100 |
commit | 9ec1caf42e7733b5141b7aecf1b6e58834a94bf7 (patch) | |
tree | cbbcc0a243186216ea675595eadeb5c6198e3436 /py/objnamedtuple.c | |
parent | 0852acfc744720cc75db9c592f947c28bd2d7e42 (diff) | |
download | micropython-9ec1caf42e7733b5141b7aecf1b6e58834a94bf7.tar.gz micropython-9ec1caf42e7733b5141b7aecf1b6e58834a94bf7.zip |
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.
Diffstat (limited to 'py/objnamedtuple.c')
-rw-r--r-- | py/objnamedtuple.c | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/py/objnamedtuple.c b/py/objnamedtuple.c index 54d8493c37..3e0f661397 100644 --- a/py/objnamedtuple.c +++ b/py/objnamedtuple.c @@ -155,6 +155,7 @@ mp_obj_namedtuple_type_t *mp_obj_new_namedtuple_base(size_t n_fields, mp_obj_t * STATIC mp_obj_t mp_obj_new_namedtuple_type(qstr name, size_t n_fields, mp_obj_t *fields) { mp_obj_namedtuple_type_t *o = mp_obj_new_namedtuple_base(n_fields, fields); o->base.base.type = &mp_type_type; + o->base.flags = MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE; // can match tuple o->base.name = name; o->base.print = namedtuple_print; o->base.make_new = namedtuple_make_new; |