Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d8b661d

Browse files
committed
Issue #10356: hash(Decimal("sNaN")) now raises ValueError instead of TypeError.
1 parent d28f790 commit d8b661d

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

Lib/decimal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ def __hash__(self):
943943
# in the documentation. (See library docs, 'Built-in Types').
944944
if self._is_special:
945945
if self.is_snan():
946-
raise TypeError('Cannot hash a signaling NaN value.')
946+
raise ValueError('Cannot hash a signaling NaN value.')
947947
elif self.is_nan():
948948
return _PyHASH_NAN
949949
else:

Lib/test/test_decimal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ def hashit(d):
13461346

13471347
#the same hash that to an int
13481348
self.assertEqual(hashit(Decimal(23)), hashit(23))
1349-
self.assertRaises(TypeError, hash, Decimal('sNaN'))
1349+
self.assertRaises(ValueError, hash, Decimal('sNaN'))
13501350
self.assertTrue(hashit(Decimal('Inf')))
13511351
self.assertTrue(hashit(Decimal('-Inf')))
13521352

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ Core and Builtins
104104
Library
105105
-------
106106

107+
- Issue #10356: hash(Decimal("sNaN")) now raises ValueError instead of
108+
TypeError.
109+
107110
- Issue #10356: Decimal.__hash__(-1) should return -2.
108111

109112
- Issue #1553375: logging: Added stack_info kwarg to display stack information.

0 commit comments

Comments
 (0)