]> granicus.if.org Git - python/commitdiff
Issue #12079: Decimal(0).fma(Decimal('inf'), 'not a number') should give a TypeError...
authorMark Dickinson <mdickinson@enthought.com>
Sun, 22 May 2011 11:53:18 +0000 (12:53 +0100)
committerMark Dickinson <mdickinson@enthought.com>
Sun, 22 May 2011 11:53:18 +0000 (12:53 +0100)
Lib/decimal.py
Lib/test/test_decimal.py
Misc/NEWS

index f5277c597cabf854a82fd1e3afd236b5eac200ef..1b11b106ea60a6fc0b4d405fe1e069422ebd1656 100644 (file)
@@ -1871,6 +1871,7 @@ class Decimal(object):
         """
 
         other = _convert_other(other, raiseit=True)
+        third = _convert_other(third, raiseit=True)
 
         # compute product; raise InvalidOperation if either operand is
         # a signaling NaN or if the product is zero times infinity.
@@ -1900,7 +1901,6 @@ class Decimal(object):
                                        str(int(self._int) * int(other._int)),
                                        self._exp + other._exp)
 
-        third = _convert_other(third, raiseit=True)
         return product.__add__(third, context)
 
     def _power_modulo(self, other, modulo, context=None):
index e46cd91e5e325fd9e1a3779bc719bfc7f35db9b9..96bbafe7395e22e1344a3d15a918afc92509e3da 100644 (file)
@@ -1970,6 +1970,17 @@ class ContextAPItests(unittest.TestCase):
         self.assertRaises(TypeError, c.fma, 2, '3', 4)
         self.assertRaises(TypeError, c.fma, 2, 3, '4')
 
+        # Issue 12079 for Context.fma ...
+        self.assertRaises(TypeError, c.fma,
+                          Decimal('Infinity'), Decimal(0), "not a decimal")
+        self.assertRaises(TypeError, c.fma,
+                          Decimal(1), Decimal('snan'), 1.222)
+        # ... and for Decimal.fma.
+        self.assertRaises(TypeError, Decimal('Infinity').fma,
+                          Decimal(0), "not a decimal")
+        self.assertRaises(TypeError, Decimal(1).fma,
+                          Decimal('snan'), 1.222)
+
     def test_is_finite(self):
         c = Context()
         d = c.is_finite(Decimal(10))
index 874f248f2ac882ce7a82151b6ded6c7a32ab32ed..b34165380c432ee61900b5abf2aacffb0be1c58a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -153,6 +153,10 @@ Core and Builtins
 Library
 -------
 
+- Issue #12079: Decimal('Infinity').fma(Decimal('0'), (3.91224318126786e+19+0j))
+  now raises TypeError (reflecting the invalid type of the 3rd argument) rather
+  than Decimal.InvalidOperation.
+
 - Issue #12124: zipimport doesn't keep a reference to zlib.decompress() anymore
   to be able to unload the module.