[issue16483] Make int(float('inf')) raise ValueError rather than OverflowError.

2012-11-15 Thread Mark Dickinson

New submission from Mark Dickinson:

[Broken out of the issue 16469 discussion about infinity -> Fraction and nan -> 
Fraction conversions.]

Conversions from float('inf') or Decimal('inf') to int (or Fraction) currently 
generate an OverflowError, while conversions from nan give a ValueError.  I'm 
of the opinion that it would make more sense for both conversions to generate 
ValueError, and I'm opening this issue to track discussion for that.  There's 
also a reasonable case that the behaviour is fine as it is, and there's little 
to be gained by changing it.

--
messages: 175642
nosy: mark.dickinson
priority: normal
severity: normal
status: open
title: Make int(float('inf')) raise ValueError rather than OverflowError.
type: enhancement
versions: Python 3.4

___
Python tracker 

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



[issue16483] Make int(float('inf')) raise ValueError rather than OverflowError.

2012-11-15 Thread Alexey Kachayev

Alexey Kachayev added the comment:

Patch is attached (ported from full issue patch for issue 16469).

--
keywords: +patch
nosy: +kachayev
Added file: http://bugs.python.org/file27993/issue16483.diff

___
Python tracker 

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



[issue16483] Make int(float('inf')) raise ValueError rather than OverflowError.

2012-11-15 Thread Case Van Horsen

Case Van Horsen added the comment:

I agree that ValueError is a more "correct" exception but I also don't think 
OverflowError is all that wrong. I don't think the change is worth the risk of 
breaking existing code.

I'd be fine with either option.

--
nosy: +casevh

___
Python tracker 

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



[issue16483] Make int(float('inf')) raise ValueError rather than OverflowError.

2012-11-16 Thread Mark Dickinson

Mark Dickinson added the comment:

I guess the feeling of wrongness for me mostly comes from the floating-point 
world, where the IEEE 754 'overflow' floating-point exception is only 
appropriate for cases where the result is *finite* but so large that it falls 
outside the representable range for a float.  Regarding conversions from 
floating-point formats to integer formats, IEEE 754 says: "When a NaN or 
infinite operand cannot be represented in the destination format and this 
cannot otherwise be indicated, the invalid operation exception shall be 
signaled." To the extent that there's a convention at all, we typically map 
'invalid operation exceptions' to ValueError.  (See the comments at the top of 
Modules/mathmodule.c.)

There's also the minor practical inconvenience of having to remember to catch 
OverflowError *and* ValueError in try: .. except: constructs.

On the other side, there's a very real possibility of breaking code with this 
change.

I'll leave this open for a week or so, but unless there's a strong consensus 
that this should be changed, I propose to close as "won't fix".

--
assignee:  -> mark.dickinson

___
Python tracker 

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



[issue16483] Make int(float('inf')) raise ValueError rather than OverflowError.

2012-11-16 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

> There's also the minor practical inconvenience of having to remember to catch 
> OverflowError *and* ValueError in try: .. except: constructs.

And MemoryError (for big decimals).

Might be the best solution would be raising an exception which subclasses both 
ValueError and OverflowError. Or make OverflowError to be subclass of 
ValueError.

--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue16483] Make int(float('inf')) raise ValueError rather than OverflowError.

2012-11-17 Thread Ramchandra Apte

Ramchandra Apte added the comment:

+1 on OverflowError being a subclass of ValueError

--
nosy: +ramchandra.apte

___
Python tracker 

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



[issue16483] Make int(float('inf')) raise ValueError rather than OverflowError.

2012-11-17 Thread Stefan Krah

Stefan Krah added the comment:

I don't particularly like OverflowError in any situation where the
potential overflow is detected *before* it actually happens. This is
another example:

 >>> x = [1]*
Traceback (most recent call last):
  File "", line 1, in 
OverflowError: cannot fit 'int' into an index-sized integer


So I agree that ValueError is more appropriate, but it may not be worth
fixing it. Closing as "won't fix" sounds fine to me.


A general exception cleanup that reduces the number of exceptions that
a user has to remember is tempting, but should probably be discussed on
python-ideas.

--
nosy: +skrah

___
Python tracker 

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



[issue16483] Make int(float('inf')) raise ValueError rather than OverflowError.

2012-11-17 Thread Andrew Svetlov

Changes by Andrew Svetlov :


--
nosy: +asvetlov

___
Python tracker 

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



[issue16483] Make int(float('inf')) raise ValueError rather than OverflowError.

2012-11-25 Thread Mark Dickinson

Mark Dickinson added the comment:

Closing as won't fix.

--
resolution:  -> wont fix
status: open -> closed

___
Python tracker 

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



[issue16483] Make int(float('inf')) raise ValueError rather than OverflowError.

2012-12-14 Thread Jesús Cea Avión

Changes by Jesús Cea Avión :


--
nosy: +jcea

___
Python tracker 

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