]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
simplify Serial hash tests; remove "equality contract" comments
authorBob Halley <halley@dnspython.org>
Sat, 27 Jun 2026 17:41:50 +0000 (10:41 -0700)
committerBob Halley <halley@dnspython.org>
Sat, 27 Jun 2026 17:41:50 +0000 (10:41 -0700)
dns/serial.py
tests/test_serial.py

index 603f5bc752e60f3bb55165ccab4a078ac0a95f7f..7ffdb1cf9eb982781ca90ec705b5aa739840023c 100644 (file)
@@ -19,9 +19,6 @@ class Serial:
         return self.value == other.value
 
     def __hash__(self):
-        # hash(self.value) satisfies the contract that a == b implies
-        # hash(a) == hash(b): Serial(v, bits) compares equal to the int v
-        # (after modular reduction), so its hash must equal hash(v).
         return hash(self.value)
 
     def __ne__(self, other):
index 64463483aeeb797ee1b42efce69919a61c962f67..c63cf6513b901d86b455419419432cf626cb2527 100644 (file)
@@ -128,21 +128,12 @@ class SerialTestCase(unittest.TestCase):
         self.assertNotEqual(S8(0), S2(0))
 
     def test_hashable(self):
-        # Serial must be hashable so it can be used in sets and as dict keys.
-        s = S8(42)
-        self.assertEqual(hash(s), hash(42))
-
-        # Equal values hash the same.
-        self.assertEqual(hash(S8(1)), hash(S8(1)))
-
         # Can be stored in a set.
         seen = {S8(0), S8(1), S8(2)}
+        self.assertIn(S8(0), seen)
         self.assertIn(S8(1), seen)
+        self.assertIn(S8(2), seen)
 
         # Can be used as a dict key.
         d = {S8(100): "zone-a"}
         self.assertEqual(d[S8(100)], "zone-a")
-
-        # hash(Serial(v)) == hash(v) (int), satisfying the equality contract.
-        self.assertEqual(hash(S8(0)), hash(0))
-        self.assertEqual(hash(S8(255)), hash(255))