]> granicus.if.org Git - python/commitdiff
Fix DeprecationWarning in tests (#4345)
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 8 Nov 2017 22:45:55 +0000 (14:45 -0800)
committerGitHub <noreply@github.com>
Wed, 8 Nov 2017 22:45:55 +0000 (14:45 -0800)
Define __hash__() in test_functools and test_itertools to fix the
following warning:

DeprecationWarning: Overriding __eq__ blocks inheritance of __hash__ in 3.x

Lib/test/test_functools.py
Lib/test/test_itertools.py

index b3372ea7c33aebf0bbff7fc24590bed437e313e8..2847573035f85a013f3d5015242c2b94a54e8dc1 100644 (file)
@@ -609,6 +609,8 @@ class TestTotalOrdering(unittest.TestCase):
                 return self.value > other.value
             def __eq__(self, other):
                 return self.value == other.value
+            def __hash__(self):
+                return hash(self.value)
         self.assertTrue(A(1) != A(2))
         self.assertFalse(A(1) != A(1))
 
@@ -620,6 +622,8 @@ class TestTotalOrdering(unittest.TestCase):
                 return self.value > other.value
             def __eq__(self, other):
                 return self.value == other.value
+            def __hash__(self):
+                return hash(self.value)
         self.assertTrue(A(1) != A(2))
         self.assertFalse(A(1) != A(1))
 
@@ -633,6 +637,8 @@ class TestTotalOrdering(unittest.TestCase):
                 return self.value == other.value
             def __ne__(self, other):
                 raise RuntimeError(self, other)
+            def __hash__(self):
+                return hash(self.value)
         with self.assertRaises(RuntimeError):
             A(1) != A(2)
         with self.assertRaises(RuntimeError):
@@ -648,6 +654,8 @@ class TestTotalOrdering(unittest.TestCase):
                 return self.value == other.value
             def __ne__(self, other):
                 raise RuntimeError(self, other)
+            def __hash__(self):
+                return hash(self.value)
         with self.assertRaises(RuntimeError):
             A(1) != A(2)
         with self.assertRaises(RuntimeError):
index 7eee81a568cc1a5ffbf8a0c7792ebdea85f0adf2..1e6db3426e4f227da26cc9a30406dfdae9e58207 100644 (file)
@@ -1491,6 +1491,8 @@ class RegressionTests(unittest.TestCase):
                 if K.i == 1:
                     next(g, None)
                 return True
+            def __hash__(self):
+                return 1
         g = next(groupby(range(10), K))[1]
         for j in range(2):
             next(g, None)  # shouldn't crash