[issue16469] Exceptions raised by Fraction() from those raised by int()

2012-11-14 Thread Mark Dickinson

Mark Dickinson added the comment:

Certainly TypeError seems inappropriate here, and using ValueError for 
conversions from NaN sounds good to me.

I'm not a big fan of the OverflowError for converting infinities to an integer: 
 nothing's actually overflowed here.  I think that should have been ValueError, 
too.  So either of ValueError or OverflowError works for me there.

I'd suggest fixing this for = 3.4 only.

--
stage:  - needs patch
versions: +Python 3.4 -Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16469
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16469] Exceptions raised by Fraction() from those raised by int()

2012-11-13 Thread Case Van Horsen

New submission from Case Van Horsen:

When attempting to convert a float(nan), float(inf), or float(-inf), 
fractions.Fraction() raises different exceptions than int()

 int(float(nan))
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: cannot convert float NaN to integer
 fractions.Fraction(float(nan))
Traceback (most recent call last):
  File stdin, line 1, in module
  File /opt/local/lib/python3.2/fractions.py, line 114, in __new__
value = Fraction.from_float(numerator)
  File /opt/local/lib/python3.2/fractions.py, line 186, in from_float
raise TypeError(Cannot convert %r to %s. % (f, cls.__name__))
TypeError: Cannot convert nan to Fraction.
 int(float(inf))
Traceback (most recent call last):
  File stdin, line 1, in module
OverflowError: cannot convert float infinity to integer
 fractions.Fraction(float(inf))
Traceback (most recent call last):
  File stdin, line 1, in module
  File /opt/local/lib/python3.2/fractions.py, line 114, in __new__
value = Fraction.from_float(numerator)
  File /opt/local/lib/python3.2/fractions.py, line 186, in from_float
raise TypeError(Cannot convert %r to %s. % (f, cls.__name__))
TypeError: Cannot convert inf to Fraction.
 int(float(-inf))
Traceback (most recent call last):
  File stdin, line 1, in module
OverflowError: cannot convert float infinity to integer
 fractions.Fraction(float(-inf))
Traceback (most recent call last):
  File stdin, line 1, in module
  File /opt/local/lib/python3.2/fractions.py, line 114, in __new__
value = Fraction.from_float(numerator)
  File /opt/local/lib/python3.2/fractions.py, line 186, in from_float
raise TypeError(Cannot convert %r to %s. % (f, cls.__name__))
TypeError: Cannot convert -inf to Fraction.

Should the exceptions be changed to ValueError and OverflowError?

--
components: Library (Lib)
messages: 175536
nosy: casevh
priority: normal
severity: normal
status: open
title: Exceptions raised by Fraction() from those raised by int()
versions: Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16469
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16469] Exceptions raised by Fraction() from those raised by int()

2012-11-13 Thread Ezio Melotti

Changes by Ezio Melotti ezio.melo...@gmail.com:


--
nosy: +ezio.melotti, mark.dickinson, rhettinger, skrah
type:  - behavior

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16469
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com