From: Bob Halley Date: Sat, 27 Jun 2026 17:41:50 +0000 (-0700) Subject: simplify Serial hash tests; remove "equality contract" comments X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4dd093561eda105618b2085bf220abe6275beeeb;p=thirdparty%2Fdnspython.git simplify Serial hash tests; remove "equality contract" comments --- diff --git a/dns/serial.py b/dns/serial.py index 603f5bc7..7ffdb1cf 100644 --- a/dns/serial.py +++ b/dns/serial.py @@ -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): diff --git a/tests/test_serial.py b/tests/test_serial.py index 64463483..c63cf651 100644 --- a/tests/test_serial.py +++ b/tests/test_serial.py @@ -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))