Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mypyc/irbuild/ll_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,10 @@ def compare_tuples(self, lhs: Value, rhs: Value, op: str, line: int = -1) -> Val
assert isinstance(lhs.type, RTuple) and isinstance(rhs.type, RTuple)
equal = True if op == "==" else False
result = Register(bool_rprimitive)
# tuples of different lengths
if len(lhs.type.types) != len(rhs.type.types):
self.add(Assign(result, self.false() if equal else self.true(), line))
return result
# empty tuples
if len(lhs.type.types) == 0 and len(rhs.type.types) == 0:
self.add(Assign(result, self.true() if equal else self.false(), line))
Expand Down
16 changes: 16 additions & 0 deletions mypyc/test-data/run-tuples.test
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,22 @@ def f7(x: List[Tuple[int, int]]) -> int:
def test_unbox_tuple() -> None:
assert f7([(5, 6)]) == 11

def test_comparison() -> None:
assert ('x','y') == ('x','y')
assert not(('x','y') != ('x','y'))

assert ('x','y') != ('x','y',1)
assert not(('x','y') == ('x','y',1))

assert ('x','y',1) != ('x','y')
assert not(('x','y',1) == ('x','y'))

assert ('x','y') != ()
assert not(('x','y') == ())

assert () != ('x','y')
assert not(() == ('x','y'))

# Test that order is irrelevant to unions. Really I only care that this builds.

class A:
Expand Down