Skip to content

Commit 8f19317

Browse files
committed
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).
1 parent db049c2 commit 8f19317

6 files changed

Lines changed: 75 additions & 10 deletions

File tree

py/objint_longlong.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ mp_obj_t mp_obj_int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
106106
return MP_BOOL(lhs_val >= rhs_val);
107107
case MP_BINARY_OP_EQUAL:
108108
return MP_BOOL(lhs_val == rhs_val);
109-
case MP_BINARY_OP_NOT_EQUAL:
110-
return MP_BOOL(lhs_val != rhs_val);
111109

112110
default:
113111
// op not supported

py/objint_mpz.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,6 @@ mp_obj_t mp_obj_int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
205205
return MP_BOOL(cmp >= 0);
206206
case MP_BINARY_OP_EQUAL:
207207
return MP_BOOL(cmp == 0);
208-
case MP_BINARY_OP_NOT_EQUAL:
209-
return MP_BOOL(cmp != 0);
210208

211209
default:
212210
return MP_OBJ_NULL;

py/objlist.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ STATIC mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
138138
case MP_BINARY_OP_MORE:
139139
case MP_BINARY_OP_MORE_EQUAL:
140140
return MP_BOOL(list_cmp_helper(op, lhs, rhs));
141-
case MP_BINARY_OP_NOT_EQUAL:
142-
return MP_BOOL(!list_cmp_helper(MP_BINARY_OP_EQUAL, lhs, rhs));
143141

144142
default:
145143
// op not supported

py/objset.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,6 @@ STATIC mp_obj_t set_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
411411
return set_issubset(lhs, rhs);
412412
case MP_BINARY_OP_MORE_EQUAL:
413413
return set_issuperset(lhs, rhs);
414-
case MP_BINARY_OP_NOT_EQUAL:
415-
return MP_BOOL(set_equal(lhs, rhs) == mp_const_false);
416414
case MP_BINARY_OP_IN:
417415
{
418416
mp_obj_set_t *o = lhs;

py/objtuple.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ mp_obj_t tuple_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
137137
case MP_BINARY_OP_MORE:
138138
case MP_BINARY_OP_MORE_EQUAL:
139139
return MP_BOOL(tuple_cmp_helper(op, lhs, rhs));
140-
case MP_BINARY_OP_NOT_EQUAL:
141-
return MP_BOOL(!tuple_cmp_helper(MP_BINARY_OP_EQUAL, lhs, rhs));
142140

143141
default:
144142
// op not supported

tests/basics/equal.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# test equality
2+
3+
print(None == None)
4+
5+
print(False == None)
6+
print(False == False)
7+
print(False == True)
8+
9+
print(() == ())
10+
print(() == [])
11+
print([] == [])
12+
print(() == {})
13+
print({} == ())
14+
15+
print(() == None)
16+
print(() == False)
17+
print(() == print)
18+
19+
print([] == None)
20+
print([] == False)
21+
print([] == print)
22+
23+
print({} == None)
24+
print({} == False)
25+
print({} == print)
26+
27+
print(1 == 1)
28+
print(1 == 2)
29+
print(1 == ())
30+
print(1 == [])
31+
print(1 == {})
32+
print(1 == 'a')
33+
34+
print('a' == 'a')
35+
print('a' == 'ab')
36+
print('a' == 1)
37+
print('a' == ())
38+
39+
# same as above but with !=
40+
41+
print(None != None)
42+
43+
print(False != None)
44+
print(False != False)
45+
print(False != True)
46+
47+
print(() != ())
48+
print(() != [])
49+
print([] != [])
50+
print(() != {})
51+
print({} != ())
52+
53+
print(() != None)
54+
print(() != False)
55+
print(() != print)
56+
57+
print([] != None)
58+
print([] != False)
59+
print([] != print)
60+
61+
print({} != None)
62+
print({} != False)
63+
print({} != print)
64+
65+
print(1 != 1)
66+
print(1 != 2)
67+
print(1 != ())
68+
print(1 != [])
69+
print(1 != {})
70+
print(1 != 'a')
71+
72+
print('a' != 'a')
73+
print('a' != 'ab')
74+
print('a' != 1)
75+
print('a' != ())

0 commit comments

Comments
 (0)