py: Remove useless implementations of NOT_EQUAL in binary_op's.

I'm pretty sure these are never reached, since NOT_EQUAL is always
converted into EQUAL in mp_binary_op.  No one should call
type.binary_op directly, they should always go through mp_binary_op
(or mp_obj_is_equal).
This commit is contained in:
Damien George 2014-04-12 00:20:39 +01:00
parent db049c2e00
commit 8f19317540
6 changed files with 75 additions and 10 deletions

View File

@ -106,8 +106,6 @@ mp_obj_t mp_obj_int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
return MP_BOOL(lhs_val >= rhs_val);
case MP_BINARY_OP_EQUAL:
return MP_BOOL(lhs_val == rhs_val);
case MP_BINARY_OP_NOT_EQUAL:
return MP_BOOL(lhs_val != rhs_val);
default:
// op not supported

View File

@ -205,8 +205,6 @@ mp_obj_t mp_obj_int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
return MP_BOOL(cmp >= 0);
case MP_BINARY_OP_EQUAL:
return MP_BOOL(cmp == 0);
case MP_BINARY_OP_NOT_EQUAL:
return MP_BOOL(cmp != 0);
default:
return MP_OBJ_NULL;

View File

@ -138,8 +138,6 @@ STATIC mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
case MP_BINARY_OP_MORE:
case MP_BINARY_OP_MORE_EQUAL:
return MP_BOOL(list_cmp_helper(op, lhs, rhs));
case MP_BINARY_OP_NOT_EQUAL:
return MP_BOOL(!list_cmp_helper(MP_BINARY_OP_EQUAL, lhs, rhs));
default:
// op not supported

View File

@ -411,8 +411,6 @@ STATIC mp_obj_t set_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
return set_issubset(lhs, rhs);
case MP_BINARY_OP_MORE_EQUAL:
return set_issuperset(lhs, rhs);
case MP_BINARY_OP_NOT_EQUAL:
return MP_BOOL(set_equal(lhs, rhs) == mp_const_false);
case MP_BINARY_OP_IN:
{
mp_obj_set_t *o = lhs;

View File

@ -137,8 +137,6 @@ mp_obj_t tuple_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
case MP_BINARY_OP_MORE:
case MP_BINARY_OP_MORE_EQUAL:
return MP_BOOL(tuple_cmp_helper(op, lhs, rhs));
case MP_BINARY_OP_NOT_EQUAL:
return MP_BOOL(!tuple_cmp_helper(MP_BINARY_OP_EQUAL, lhs, rhs));
default:
// op not supported

75
tests/basics/equal.py Normal file
View File

@ -0,0 +1,75 @@
# test equality
print(None == None)
print(False == None)
print(False == False)
print(False == True)
print(() == ())
print(() == [])
print([] == [])
print(() == {})
print({} == ())
print(() == None)
print(() == False)
print(() == print)
print([] == None)
print([] == False)
print([] == print)
print({} == None)
print({} == False)
print({} == print)
print(1 == 1)
print(1 == 2)
print(1 == ())
print(1 == [])
print(1 == {})
print(1 == 'a')
print('a' == 'a')
print('a' == 'ab')
print('a' == 1)
print('a' == ())
# same as above but with !=
print(None != None)
print(False != None)
print(False != False)
print(False != True)
print(() != ())
print(() != [])
print([] != [])
print(() != {})
print({} != ())
print(() != None)
print(() != False)
print(() != print)
print([] != None)
print([] != False)
print([] != print)
print({} != None)
print({} != False)
print({} != print)
print(1 != 1)
print(1 != 2)
print(1 != ())
print(1 != [])
print(1 != {})
print(1 != 'a')
print('a' != 'a')
print('a' != 'ab')
print('a' != 1)
print('a' != ())