@@ -467,6 +467,35 @@ mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
467467 // then fail
468468 // note that list does not implement + or +=, so that inplace_concat is reached first for +=
469469
470+ // deal with == and != for all types
471+ if (op == RT_COMPARE_OP_EQUAL || op == RT_COMPARE_OP_NOT_EQUAL ) {
472+ if (mp_obj_equal (lhs , rhs )) {
473+ if (op == RT_COMPARE_OP_EQUAL ) {
474+ return mp_const_true ;
475+ } else {
476+ return mp_const_false ;
477+ }
478+ } else {
479+ if (op == RT_COMPARE_OP_EQUAL ) {
480+ return mp_const_false ;
481+ } else {
482+ return mp_const_true ;
483+ }
484+ }
485+ }
486+
487+ // deal with exception_match for all types
488+ if (op == RT_COMPARE_OP_EXCEPTION_MATCH ) {
489+ // TODO properly! at the moment it just compares the exception identifier for equality
490+ if (MP_OBJ_IS_TYPE (lhs , & exception_type ) && MP_OBJ_IS_TYPE (rhs , & exception_type )) {
491+ if (mp_obj_exception_get_type (lhs ) == mp_obj_exception_get_type (rhs )) {
492+ return mp_const_true ;
493+ } else {
494+ return mp_const_false ;
495+ }
496+ }
497+ }
498+
470499 if (MP_OBJ_IS_SMALL_INT (lhs )) {
471500 mp_small_int_t lhs_val = MP_OBJ_SMALL_INT_VALUE (lhs );
472501 if (MP_OBJ_IS_SMALL_INT (rhs )) {
@@ -530,35 +559,6 @@ mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
530559 return mp_obj_complex_binary_op (op , lhs_val , 0 , rhs );
531560 }
532561 } else {
533- // deal with == and !=
534- if (op == RT_COMPARE_OP_EQUAL || op == RT_COMPARE_OP_NOT_EQUAL ) {
535- if (mp_obj_equal (lhs , rhs )) {
536- if (op == RT_COMPARE_OP_EQUAL ) {
537- return mp_const_true ;
538- } else {
539- return mp_const_false ;
540- }
541- } else {
542- if (op == RT_COMPARE_OP_EQUAL ) {
543- return mp_const_false ;
544- } else {
545- return mp_const_true ;
546- }
547- }
548- }
549-
550- // deal with exception_match
551- if (op == RT_COMPARE_OP_EXCEPTION_MATCH ) {
552- // TODO properly! at the moment it just compares the exception identifier for equality
553- if (MP_OBJ_IS_TYPE (lhs , & exception_type ) && MP_OBJ_IS_TYPE (rhs , & exception_type )) {
554- if (mp_obj_exception_get_type (lhs ) == mp_obj_exception_get_type (rhs )) {
555- return mp_const_true ;
556- } else {
557- return mp_const_false ;
558- }
559- }
560- }
561-
562562 if (MP_OBJ_IS_OBJ (lhs )) {
563563 mp_obj_base_t * o = lhs ;
564564 if (o -> type -> binary_op != NULL ) {
0 commit comments