From: Stefan Krah Date: Thu, 18 Nov 2010 15:20:34 +0000 (+0000) Subject: Issue #10356: hash(Decimal("sNaN")) now raises ValueError instead of TypeError. X-Git-Tag: v3.2b1~340 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d8b661dd908629b5fc0f50e3e0c5fc5c85f9cb72;p=thirdparty%2FPython%2Fcpython.git Issue #10356: hash(Decimal("sNaN")) now raises ValueError instead of TypeError. --- diff --git a/Lib/decimal.py b/Lib/decimal.py index 5a9f84077114..b78c2c577418 100644 --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -943,7 +943,7 @@ class Decimal(object): # in the documentation. (See library docs, 'Built-in Types'). if self._is_special: if self.is_snan(): - raise TypeError('Cannot hash a signaling NaN value.') + raise ValueError('Cannot hash a signaling NaN value.') elif self.is_nan(): return _PyHASH_NAN else: diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py index 611ef5500733..b07fb1ddb872 100644 --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -1346,7 +1346,7 @@ class DecimalUsabilityTest(unittest.TestCase): #the same hash that to an int self.assertEqual(hashit(Decimal(23)), hashit(23)) - self.assertRaises(TypeError, hash, Decimal('sNaN')) + self.assertRaises(ValueError, hash, Decimal('sNaN')) self.assertTrue(hashit(Decimal('Inf'))) self.assertTrue(hashit(Decimal('-Inf'))) diff --git a/Misc/NEWS b/Misc/NEWS index ae26a990b9a3..8ab404d88f47 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -104,6 +104,9 @@ Core and Builtins Library ------- +- Issue #10356: hash(Decimal("sNaN")) now raises ValueError instead of + TypeError. + - Issue #10356: Decimal.__hash__(-1) should return -2. - Issue #1553375: logging: Added stack_info kwarg to display stack information.