Skip to content

Commit 1c6c908

Browse files
committed
Simplify comparison of float tuple elements
1 parent cb3bddd commit 1c6c908

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

mypyc/irbuild/ll_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,7 @@ def compare_tuples(self, lhs: Value, rhs: Value, op: str, line: int = -1) -> Val
15341534
compare = self.binary_op(lhs_item, rhs_item, op, line)
15351535
# Cast to bool if necessary since most types uses comparison returning a object type
15361536
# See generic_ops.py for more information
1537-
if not is_bool_rprimitive(compare.type):
1537+
if not (is_bool_rprimitive(compare.type) or is_bit_rprimitive(compare.type)):
15381538
compare = self.primitive_op(bool_op, [compare], line)
15391539
if i < len(lhs.type.types) - 1:
15401540
branch = Branch(compare, early_stop, check_blocks[i + 1], Branch.BOOL)

mypyc/test-data/irbuild-tuple.test

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,3 +453,26 @@ L0:
453453
r0 = CPySequence_Multiply(a, 4)
454454
b = r0
455455
return 1
456+
457+
[case testTupleFloatElementComparison]
458+
def f(x: tuple[float], y: tuple[float]) -> bool:
459+
return x == y
460+
461+
[out]
462+
def f(x, y):
463+
x, y :: tuple[float]
464+
r0, r1 :: float
465+
r2 :: bit
466+
r3 :: bool
467+
L0:
468+
r0 = x[0]
469+
r1 = y[0]
470+
r2 = r0 == r1
471+
if not r2 goto L1 else goto L2 :: bool
472+
L1:
473+
r3 = 0
474+
goto L3
475+
L2:
476+
r3 = 1
477+
L3:
478+
return r3

0 commit comments

Comments
 (0)