Backport 1.8 3800

Backport #3800: `BUG: fix hashing of long integers under python3`.