summaryrefslogtreecommitdiffstats
path: root/Lib/fractions.py
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-11-13 10:27:38 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2010-11-13 10:27:38 (GMT)
commitfec6620dfb9b7e99b68c07b623235f87f5fd1a60 (patch)
tree36c6d0c627256a1dd1efb9d866e232271336d77b /Lib/fractions.py
parent24854cac996ebe2f534cbe58b141fe51fd2d8d0e (diff)
downloadcpython-fec6620dfb9b7e99b68c07b623235f87f5fd1a60.zip
cpython-fec6620dfb9b7e99b68c07b623235f87f5fd1a60.tar.gz
cpython-fec6620dfb9b7e99b68c07b623235f87f5fd1a60.tar.bz2
Make Fraction(-1).__hash__() return -2 rather than -1 (see issue 10356).
Diffstat (limited to 'Lib/fractions.py')
-rw-r--r--Lib/fractions.py9
1 files changed, 3 insertions, 6 deletions
diff --git a/Lib/fractions.py b/Lib/fractions.py
index 51e67e2..8be52d2 100644
--- a/Lib/fractions.py
+++ b/Lib/fractions.py
@@ -528,12 +528,8 @@ class Fraction(numbers.Rational):
return Fraction(round(self / shift) * shift)
def __hash__(self):
- """hash(self)
+ """hash(self)"""
- Tricky because values that are exactly representable as a
- float must have the same hash as that float.
-
- """
# XXX since this method is expensive, consider caching the result
# In order to make sure that the hash of a Fraction agrees
@@ -550,7 +546,8 @@ class Fraction(numbers.Rational):
hash_ = _PyHASH_INF
else:
hash_ = abs(self._numerator) * dinv % _PyHASH_MODULUS
- return hash_ if self >= 0 else -hash_
+ result = hash_ if self >= 0 else -hash_
+ return -2 if result == -1 else result
def __eq__(a, b):
"""a == b"""