Skip to content

Commit 08d7ba9

Browse files
committed
review comments
1 parent fec9fbe commit 08d7ba9

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Lib/test/test_long.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,10 +1696,18 @@ class MyInt(int):
16961696
def test_hash(self):
16971697
# gh-136599
16981698
self.assertEqual(hash(-1), -2)
1699+
self.assertEqual(hash(0), 0)
16991700
self.assertEqual(hash(10), 10)
1700-
self.assertEqual(hash(2**31 - 2), 2**31 - 2)
1701-
self.assertNotEqual(hash(-2**31), -1)
1702-
self.assertNotEqual(hash(-2**61), -1)
1701+
1702+
self.assertEqual(hash(sys.hash_info.modulus - 2), sys.hash_info.modulus - 2)
1703+
self.assertEqual(hash(sys.hash_info.modulus - 1), sys.hash_info.modulus - 1)
1704+
self.assertEqual(hash(sys.hash_info.modulus), 0)
1705+
self.assertEqual(hash(sys.hash_info.modulus + 1), 1)
1706+
1707+
self.assertEqual(hash(-sys.hash_info.modulus - 2), -2)
1708+
self.assertEqual(hash(-sys.hash_info.modulus - 1), -2)
1709+
self.assertEqual(hash(-sys.hash_info.modulus), 0)
1710+
self.assertEqual(hash(-sys.hash_info.modulus + 1), - (sys.hash_info.modulus - 1))
17031711

17041712

17051713
if __name__ == "__main__":

Objects/longobject.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3678,11 +3678,13 @@ long_hash(PyObject *obj)
36783678
sign = _PyLong_NonCompactSign(v);
36793679

36803680
// unroll first two digits
3681+
#if ( PyHASH_BITS > PyLong_SHIFT )
36813682
assert(i>=2);
36823683
--i;
36833684
x = v->long_value.ob_digit[i];
36843685
assert(x < _PyHASH_MODULUS);
3685-
#if ( PyHASH_BITS > (2*PyLong_SHIFT))
3686+
#endif
3687+
#if ( PyHASH_BITS > (2 * PyLong_SHIFT) )
36863688
--i;
36873689
x = ((x << PyLong_SHIFT));
36883690
x += v->long_value.ob_digit[i];

0 commit comments

Comments
 (0)