diff options
author | Jon Bjarni Bjarnason <jbbjarnason@gmail.com> | 2022-04-12 22:17:38 +0000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2022-04-20 15:44:46 +1000 |
commit | 1ded8a2977a84777f339ea7e7c788b11d75a6cce (patch) | |
tree | c48babcbeea93711fabd3394013b8519f7f8c00c /py/objtype.c | |
parent | 52c2580a403a8259eabcd1bd1f9911c0ac4efd4c (diff) |
py/objtype: Convert result of user __contains__ method to bool.
Per https://docs.python.org/3/reference/expressions.html#membership-test-operations
For user-defined classes which define the contains() method, x in y
returns True if y.contains(x) returns a true value, and False
otherwise.
Fixes issue #7884.
Diffstat (limited to 'py/objtype.c')
-rw-r--r-- | py/objtype.c | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/py/objtype.c b/py/objtype.c index 0977a67ce..e320adc8b 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -549,6 +549,7 @@ retry:; } else if (dest[0] != MP_OBJ_NULL) { dest[2] = rhs_in; res = mp_call_method_n_kw(1, 0, dest); + res = op == MP_BINARY_OP_CONTAINS ? mp_obj_new_bool(mp_obj_is_true(res)) : res; } else { // If this was an inplace method, fallback to normal method // https://docs.python.org/3/reference/datamodel.html#object.__iadd__ : |