8000 Consider ellipsis in TupleMeta.__eq__ (#201) · python/typing@a22b68e · GitHub
[go: up one dir, main page]

Skip to content

Commit a22b68e

Browse files
bintorogvanrossum
authored andcommitted
Consider ellipsis in TupleMeta.__eq__ (#201)
1 parent 88a0ac6 commit a22b68e

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

python2/test_typing.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,12 @@ def test_basics(self):
358358
self.assertTrue(issubclass(tuple, Tuple))
359359
self.assertFalse(issubclass(Tuple, tuple)) # Can't have it both ways.
360360

361+
def test_equality(self):
362+
assert Tuple[int] == Tuple[int]
363+
assert Tuple[int, ...] == Tuple[int, ...]
364+
assert Tuple[int] != Tuple[int, int]
365+
assert Tuple[int] != Tuple[int, ...]
366+
361367
def test_tuple_subclass(self):
362368
class MyTuple(tuple):
363369
pass

python2/typing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,8 @@ def __getitem__(self, parameters):
718718
def __eq__(self, other):
719719
if not isinstance(other, TupleMeta):
720720
return NotImplemented
721-
return self.__tuple_params__ == other.__tuple_params__
721+
return (self.__tuple_params__ == other.__tuple_params__ and
722+
self.__tuple_use_ellipsis__ == other.__tuple_use_ellipsis__)
722723

723724
def __hash__(self):
724725
return hash(self.__tuple_params__)

src/test_typing.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,12 @@ def test_basics(self):
359359
self.assertTrue(issubclass(tuple, Tuple))
360360
self.assertFalse(issubclass(Tuple, tuple)) # Can't have it both ways.
361361

362+
def test_equality(self):
363+
assert Tuple[int] == Tuple[int]
364+
assert Tuple[int, ...] == Tuple[int, ...]
365+
assert Tuple[int] != Tuple[int, int]
366+
assert Tuple[int] != Tuple[int, ...]
367+
362368
def test_tuple_subclass(self):
363369
class MyTuple(tuple):
364370
pass

src/typing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,8 @@ def __getitem__(self, parameters):
705705
def __eq__(self, other):
706706
if not isinstance(other, TupleMeta):
707707
return NotImplemented
708-
return self.__tuple_params__ == other.__tuple_params__
708+
return (self.__tuple_params__ == other.__tuple_params__ and
709+
self.__tuple_use_ellipsis__ == other.__tuple_use_ellipsis__)
709710

710711
def __hash__(self):
711712
return hash(self.__tuple_params__)

0 commit comments

Comments
 (0)
0