@@ -78,6 +78,11 @@ def _deep_contains(node_or_list, node):
7878
7979COMMUTATIVE_OPS = {"add" , "mul" , "eq" , "ne" , "and" , "or" , "xor" }
8080COMPARISON_OPS = {"gt" , "sgt" , "ge" , "sge" , "lt" , "slt" , "le" , "sle" }
81+ STRICT_COMPARISON_OPS = {t for t in COMPARISON_OPS if t .endswith ("t" )}
82+ UNSTRICT_COMPARISON_OPS = {t for t in COMPARISON_OPS if t .endswith ("e" )}
83+
84+ assert not (STRICT_COMPARISON_OPS & UNSTRICT_COMPARISON_OPS )
85+ assert STRICT_COMPARISON_OPS | UNSTRICT_COMPARISON_OPS == COMPARISON_OPS
8186
8287
8388def _flip_comparison_op (opname ):
@@ -255,11 +260,15 @@ def _conservative_eq(x, y):
255260 # x + 0 == x - 0 == x | 0 == x ^ 0 == x
256261 return finalize ("seq" , [args [0 ]])
257262
258- if binop in {"sub" , "xor" , "ne" , "lt" , "gt" } and _conservative_eq (args [0 ], args [1 ]):
259- # (x - x) == (x ^ x) == (x != x) == (x < x) == (x > x) == 0
263+ if binop in {"sub" , "xor" , "ne" } and _conservative_eq (args [0 ], args [1 ]):
264+ # (x - x) == (x ^ x) == (x != x) == 0
265+ return finalize (0 , [])
266+
267+ if binop in STRICT_COMPARISON_OPS and _conservative_eq (args [0 ], args [1 ]):
268+ # (x < x) == (x > x) == 0
260269 return finalize (0 , [])
261270
262- if binop in ( "eq" , "le" , "ge" ) and _conservative_eq (args [0 ], args [1 ]):
271+ if binop in { "eq" } | UNSTRICT_COMPARISON_OPS and _conservative_eq (args [0 ], args [1 ]):
263272 # (x == x) == (x >= x) == (x <= x) == 1
264273 return finalize (1 , [])
265274
0 commit comments