Anonymous avatar Anonymous committed 4db5ea9

Decimal special values did not hash properly.

Comments (0)

Files changed (3)

         # Decimal integers must hash the same as the ints
         # Non-integer decimals are normalized and hashed as strings
         # Normalization assures that hast(100E-1) == hash(10)
+        if self._is_special:
+            if self._isnan():
+                raise TypeError('Cannot hash a NaN value.')
+            return hash(str(self))
         i = int(self)
         if self == Decimal(i):
             return hash(i)

Lib/test/test_decimal.py

         hash(Decimal(23))
         #the same hash that to an int
         self.assertEqual(hash(Decimal(23)), hash(23))
+        self.assertRaises(TypeError, hash, Decimal('NaN'))
+        self.assert_(hash(Decimal('Inf')))
+        self.assert_(hash(Decimal('-Inf')))
 
     def test_min_and_max_methods(self):
 
 Library
 -------
 
+- Bug #1163325:  Decimal infinities failed to hash.  Attempting to
+  hash a NaN raised an InvalidOperation instead of a TypeError.
+
 - Bug #1160802: can't build Zope on Windows with 2.4.1c1.  The
   ``MSVCCompiler`` class in distutils forgot to record that it was
   initialized, and continued adding redundant entries to the system
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.