Skip to content

Commit a48860f

Browse files
committed
review comments
1 parent 194fb7a commit a48860f

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Lib/test/test_long.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,11 +1693,14 @@ class MyInt(int):
16931693
# GH-117195 -- This shouldn't crash
16941694
object.__sizeof__(1)
16951695

1696-
def test_long_hash(self):
1696+
def test_hash(self):
16971697
# gh-136599
1698-
assert hash(10) == 10
1699-
assert hash(-1) == -2
1700-
assert hash(-2**61) != -1
1698+
self.assertEqual(hash(-1), -2)
1699+
self.assertEqual(hash(10), 10)
1700+
self.assertEqual(hash(2**31 -1), 2**31 - 1)
1701+
self.assertNotEqual(hash(-2**31), -1)
1702+
self.assertNotEqual(hash(-2**61), -1)
1703+
17011704

17021705
if __name__ == "__main__":
17031706
unittest.main()

Objects/longobject.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3682,11 +3682,12 @@ long_hash(PyObject *obj)
36823682
--i;
36833683
x = v->long_value.ob_digit[i];
36843684
assert(x < _PyHASH_MODULUS);
3685+
#if ( PyHASH_BITS > (2*PyLong_SHIFT))
36853686
--i;
36863687
x = ((x << PyLong_SHIFT));
36873688
x += v->long_value.ob_digit[i];
36883689
assert(x < _PyHASH_MODULUS);
3689-
3690+
#endif
36903691
while (--i >= 0) {
36913692
/* Here x is a quantity in the range [0, _PyHASH_MODULUS); we
36923693
want to compute x * 2**PyLong_SHIFT + v->long_value.ob_digit[i] modulo

0 commit comments

Comments
 (0)