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

Skip to content

Commit b455e58

Browse files
committed
Issue #12079: Decimal(0).fma(Decimal('inf'), 'not a number') should give a TypeError, not a Decimal.InvalidOperation
1 parent 203bdb3 commit b455e58

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

Lib/decimal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1871,6 +1871,7 @@ def fma(self, other, third, context=None):
18711871
"""
18721872

18731873
other = _convert_other(other, raiseit=True)
1874+
third = _convert_other(third, raiseit=True)
18741875

18751876
# compute product; raise InvalidOperation if either operand is
18761877
# a signaling NaN or if the product is zero times infinity.
@@ -1900,7 +1901,6 @@ def fma(self, other, third, context=None):
19001901
str(int(self._int) * int(other._int)),
19011902
self._exp + other._exp)
19021903

1903-
third = _convert_other(third, raiseit=True)
19041904
return product.__add__(third, context)
19051905

19061906
def _power_modulo(self, other, modulo, context=None):

Lib/test/test_decimal.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,6 +1970,17 @@ def test_fma(self):
19701970
self.assertRaises(TypeError, c.fma, 2, '3', 4)
19711971
self.assertRaises(TypeError, c.fma, 2, 3, '4')
19721972

1973+
# Issue 12079 for Context.fma ...
1974+
self.assertRaises(TypeError, c.fma,
1975+
Decimal('Infinity'), Decimal(0), "not a decimal")
1976+
self.assertRaises(TypeError, c.fma,
1977+
Decimal(1), Decimal('snan'), 1.222)
1978+
# ... and for Decimal.fma.
1979+
self.assertRaises(TypeError, Decimal('Infinity').fma,
1980+
Decimal(0), "not a decimal")
1981+
self.assertRaises(TypeError, Decimal(1).fma,
1982+
Decimal('snan'), 1.222)
1983+
19731984
def test_is_finite(self):
19741985
c = Context()
19751986
d = c.is_finite(Decimal(10))

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ Core and Builtins
153153
Library
154154
-------
155155

156+
- Issue #12079: Decimal('Infinity').fma(Decimal('0'), (3.91224318126786e+19+0j))
157+
now raises TypeError (reflecting the invalid type of the 3rd argument) rather
158+
than Decimal.InvalidOperation.
159+
156160
- Issue #12124: zipimport doesn't keep a reference to zlib.decompress() anymore
157161
to be able to unload the module.
158162

0 commit comments

Comments
 (0)