summaryrefslogtreecommitdiffstatshomepage
path: root/py/runtime.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-11-24 12:07:12 +1100
committerDamien George <damien.p.george@gmail.com>2017-11-24 12:07:12 +1100
commit9783ac282ebe216d37be39fdf07113e6880c19b7 (patch)
tree62fe616966547115541e050a3588ad65b56a97fe /py/runtime.c
parent067bf849d29ab46319740a10561a112376415f51 (diff)
downloadmicropython-9783ac282ebe216d37be39fdf07113e6880c19b7.tar.gz
micropython-9783ac282ebe216d37be39fdf07113e6880c19b7.zip
py/runtime: Simplify handling of containment binary operator.
In mp_binary_op, there is no need to explicitly check for type->getiter being non-null and raising an exception because this is handled exactly by mp_getiter(). So just call the latter unconditionally.
Diffstat (limited to 'py/runtime.c')
-rw-r--r--py/runtime.c26
1 files changed, 9 insertions, 17 deletions
diff --git a/py/runtime.c b/py/runtime.c
index 17e5d235c9..08a35c2e60 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -536,25 +536,17 @@ mp_obj_t mp_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) {
return res;
}
}
- if (type->getiter != NULL) {
- /* second attempt, walk the iterator */
- mp_obj_iter_buf_t iter_buf;
- mp_obj_t iter = mp_getiter(rhs, &iter_buf);
- mp_obj_t next;
- while ((next = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) {
- if (mp_obj_equal(next, lhs)) {
- return mp_const_true;
- }
- }
- return mp_const_false;
- }
- if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
- mp_raise_TypeError("object not iterable");
- } else {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
- "'%s' object is not iterable", mp_obj_get_type_str(rhs)));
+ // final attempt, walk the iterator (will raise if rhs is not iterable)
+ mp_obj_iter_buf_t iter_buf;
+ mp_obj_t iter = mp_getiter(rhs, &iter_buf);
+ mp_obj_t next;
+ while ((next = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) {
+ if (mp_obj_equal(next, lhs)) {
+ return mp_const_true;
+ }
}
+ return mp_const_false;
}
// generic binary_op supplied by type