[Python-checkins] cpython (3.5): typing.py: Consider ellipsis in TupleMeta.__eq__. By Kalle Tuure.

guido.van.rossum python-checkins at python.org
Mon Apr 18 10:40:12 EDT 2016


https://hg.python.org/cpython/rev/9e9f01260b27
changeset:   101050:9e9f01260b27
branch:      3.5
parent:      101048:730a95c2d38f
user:        Guido van Rossum <guido at python.org>
date:        Mon Apr 18 07:37:41 2016 -0700
summary:
  typing.py: Consider ellipsis in TupleMeta.__eq__. By Kalle Tuure. github.com/python/typing/pull/201.

files:
  Lib/test/test_typing.py |  6 ++++++
  Lib/typing.py           |  3 ++-
  2 files changed, 8 insertions(+), 1 deletions(-)


diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -359,6 +359,12 @@
         self.assertTrue(issubclass(tuple, Tuple))
         self.assertFalse(issubclass(Tuple, tuple))  # Can't have it both ways.
 
+    def test_equality(self):
+        assert Tuple[int] == Tuple[int]
+        assert Tuple[int, ...] == Tuple[int, ...]
+        assert Tuple[int] != Tuple[int, int]
+        assert Tuple[int] != Tuple[int, ...]
+
     def test_tuple_subclass(self):
         class MyTuple(tuple):
             pass
diff --git a/Lib/typing.py b/Lib/typing.py
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -705,7 +705,8 @@
     def __eq__(self, other):
         if not isinstance(other, TupleMeta):
             return NotImplemented
-        return self.__tuple_params__ == other.__tuple_params__
+        return (self.__tuple_params__ == other.__tuple_params__ and
+                self.__tuple_use_ellipsis__ == other.__tuple_use_ellipsis__)
 
     def __hash__(self):
         return hash(self.__tuple_params__)

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list