Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[mypyc] Fix comparison of tuples with different lengths#19372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JukkaL merged 2 commits intopython:masterfromp-sawicki:p-sawicki/tuple-comparison
Jul 4, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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 deletionsmypyc/irbuild/ll_builder.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionsmypyc/test-data/run-tuples.test
View file
Open in desktop
Original file line numberDiff line numberDiff 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

[8]ページ先頭

©2009-2025 Movatter.jp