@@ -146,9 +146,10 @@ def testInitFromFloat(self):
146146 self .assertEqual ((0 , 1 ), _components (F (- 0.0 )))
147147 self .assertEqual ((3602879701896397 , 36028797018963968 ),
148148 _components (F (0.1 )))
149- self .assertRaises (TypeError , F , float ('nan' ))
150- self .assertRaises (TypeError , F , float ('inf' ))
151- self .assertRaises (TypeError , F , float ('-inf' ))
149+ # bug 16469: error types should be consistent with float -> int
150+ self .assertRaises (ValueError , F , float ('nan' ))
151+ self .assertRaises (OverflowError , F , float ('inf' ))
152+ self .assertRaises (OverflowError , F , float ('-inf' ))
152153
153154 def testInitFromDecimal (self ):
154155 self .assertEqual ((11 , 10 ),
@@ -157,10 +158,11 @@ def testInitFromDecimal(self):
157158 _components (F (Decimal ('3.5e-2' ))))
158159 self .assertEqual ((0 , 1 ),
159160 _components (F (Decimal ('.000e20' ))))
160- self .assertRaises (TypeError , F , Decimal ('nan' ))
161- self .assertRaises (TypeError , F , Decimal ('snan' ))
162- self .assertRaises (TypeError , F , Decimal ('inf' ))
163- self .assertRaises (TypeError , F , Decimal ('-inf' ))
161+ # bug 16469: error types should be consistent with decimal -> int
162+ self .assertRaises (ValueError , F , Decimal ('nan' ))
163+ self .assertRaises (ValueError , F , Decimal ('snan' ))
164+ self .assertRaises (OverflowError , F , Decimal ('inf' ))
165+ self .assertRaises (OverflowError , F , Decimal ('-inf' ))
164166
165167 def testFromString (self ):
166168 self .assertEqual ((5 , 1 ), _components (F ("5" )))
@@ -248,14 +250,15 @@ def testFromFloat(self):
248250
249251 inf = 1e1000
250252 nan = inf - inf
253+ # bug 16469: error types should be consistent with float -> int
251254 self .assertRaisesMessage (
252- TypeError , "Cannot convert inf to Fraction." ,
255+ OverflowError , "Cannot convert inf to Fraction." ,
253256 F .from_float , inf )
254257 self .assertRaisesMessage (
255- TypeError , "Cannot convert -inf to Fraction." ,
258+ OverflowError , "Cannot convert -inf to Fraction." ,
256259 F .from_float , - inf )
257260 self .assertRaisesMessage (
258- TypeError , "Cannot convert nan to Fraction." ,
261+ ValueError , "Cannot convert nan to Fraction." ,
259262 F .from_float , nan )
260263
261264 def testFromDecimal (self ):
@@ -268,17 +271,18 @@ def testFromDecimal(self):
268271 self .assertEqual (1 - F (1 , 10 ** 30 ),
269272 F .from_decimal (Decimal ("0." + "9" * 30 )))
270273
274+ # bug 16469: error types should be consistent with decimal -> int
271275 self .assertRaisesMessage (
272- TypeError , "Cannot convert Infinity to Fraction." ,
276+ OverflowError , "Cannot convert Infinity to Fraction." ,
273277 F .from_decimal , Decimal ("inf" ))
274278 self .assertRaisesMessage (
275- TypeError , "Cannot convert -Infinity to Fraction." ,
279+ OverflowError , "Cannot convert -Infinity to Fraction." ,
276280 F .from_decimal , Decimal ("-inf" ))
277281 self .assertRaisesMessage (
278- TypeError , "Cannot convert NaN to Fraction." ,
282+ ValueError , "Cannot convert NaN to Fraction." ,
279283 F .from_decimal , Decimal ("nan" ))
280284 self .assertRaisesMessage (
281- TypeError , "Cannot convert sNaN to Fraction." ,
285+ ValueError , "Cannot convert sNaN to Fraction." ,
282286 F .from_decimal , Decimal ("snan" ))
283287
284288 def testLimitDenominator (self ):
0 commit comments