Python documentation describes hashing procedure of fractions (and ints, and floats) here.
I understand the approach as far as 'treat fractions as mod P' and 'inverses mod P are easyish to compute'. Afterwards encode sign by negating hash when appropriate.
There is a additional rule:
If x = m / n is a negative rational number define hash(x) as -hash(-x). If the resulting hash is -1, replace it with -2.
This makes no sense to me since it leads to
hash(-1) == hash(-2)
Surely getting distinct values on common inputs is rather important for a good hash function!
How come this is a better choice than hash(-1) == -1
?
The implementation in cPython gives no comments to this odd choice either.