GH-84783: Make the slice object hashable (GH-101264)

This commit is contained in:
Furkan Onder 2023-02-19 00:22:02 +00:00 committed by GitHub
parent 5170caf305
commit 61f1e67c6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 53 additions and 12 deletions

View file

@ -80,10 +80,16 @@ class SliceTest(unittest.TestCase):
self.assertEqual(repr(slice(1, 2, 3)), "slice(1, 2, 3)")
def test_hash(self):
# Verify clearing of SF bug #800796
self.assertRaises(TypeError, hash, slice(5))
self.assertEqual(hash(slice(5)), slice(5).__hash__())
self.assertEqual(hash(slice(1, 2)), slice(1, 2).__hash__())
self.assertEqual(hash(slice(1, 2, 3)), slice(1, 2, 3).__hash__())
self.assertNotEqual(slice(5), slice(6))
with self.assertRaises(TypeError):
slice(5).__hash__()
hash(slice(1, 2, []))
with self.assertRaises(TypeError):
hash(slice(4, {}))
def test_cmp(self):
s1 = slice(1, 2, 3)