mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Issue #7279: Make Decimal('nan') hashable. Decimal('snan') remains unhashable.
Also rewrite the Decimal __hash__ method so that it doesn't rely on float('inf') being valid: float('inf') could raise an exception on platforms not using IEEE 754 arithmetic.
This commit is contained in:
parent
e096e82e82
commit
f3eeca16cb
3 changed files with 27 additions and 6 deletions
|
@ -1274,6 +1274,10 @@ class DecimalUsabilityTest(unittest.TestCase):
|
|||
def test_hash_method(self):
|
||||
#just that it's hashable
|
||||
hash(Decimal(23))
|
||||
hash(Decimal('Infinity'))
|
||||
hash(Decimal('-Infinity'))
|
||||
hash(Decimal('nan123'))
|
||||
hash(Decimal('-NaN'))
|
||||
|
||||
test_values = [Decimal(sign*(2**m + n))
|
||||
for m in [0, 14, 15, 16, 17, 30, 31,
|
||||
|
@ -1308,7 +1312,7 @@ class DecimalUsabilityTest(unittest.TestCase):
|
|||
|
||||
#the same hash that to an int
|
||||
self.assertEqual(hash(Decimal(23)), hash(23))
|
||||
self.assertRaises(TypeError, hash, Decimal('NaN'))
|
||||
self.assertRaises(TypeError, hash, Decimal('sNaN'))
|
||||
self.assertTrue(hash(Decimal('Inf')))
|
||||
self.assertTrue(hash(Decimal('-Inf')))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue