diff options
author | Damien George <damien.p.george@gmail.com> | 2017-11-24 13:04:24 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-11-24 14:48:23 +1100 |
commit | 5e34a113eaaf736fb4f703a3ee0892e1705d0a63 (patch) | |
tree | 835e0a77f839a4bcffb689c901d989957dced749 /py/objint_mpz.c | |
parent | 5b2f62aff312949c9c7edec6cfaaf4f97d93c442 (diff) |
py/runtime: Add MP_BINARY_OP_CONTAINS as reverse of MP_BINARY_OP_IN.
Before this patch MP_BINARY_OP_IN had two meanings: coming from bytecode it
meant that the args needed to be swapped, but coming from within the
runtime meant that the args were already in the correct order. This lead
to some confusion in the code and comments stating how args were reversed.
It also lead to 2 bugs: 1) containment for a subclass of a native type
didn't work; 2) the expression "{True} in True" would illegally succeed and
return True. In both of these cases it was because the args to
MP_BINARY_OP_IN ended up being reversed twice.
To fix these things this patch introduces MP_BINARY_OP_CONTAINS which
corresponds exactly to the __contains__ special method, and this is the
operator that built-in types should implement. MP_BINARY_OP_IN is now only
emitted by the compiler and is converted to MP_BINARY_OP_CONTAINS by
swapping the arguments.
Diffstat (limited to 'py/objint_mpz.c')
-rw-r--r-- | py/objint_mpz.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/py/objint_mpz.c b/py/objint_mpz.c index 7b5cb0b9d..17e3ee6d2 100644 --- a/py/objint_mpz.c +++ b/py/objint_mpz.c @@ -207,7 +207,7 @@ mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_i return mp_obj_new_float(flhs / frhs); #endif - } else if (op >= MP_BINARY_OP_INPLACE_OR) { + } else if (op >= MP_BINARY_OP_INPLACE_OR && op < MP_BINARY_OP_CONTAINS) { mp_obj_int_t *res = mp_obj_int_new_mpz(); switch (op) { |