[issue22951] unexpected return from float.__repr__() for inf, -inf, nan

Mark Dickinson report at bugs.python.org
Thu Nov 27 13:07:26 CET 2014


Mark Dickinson added the comment:

A couple of points against this change:

1. If repr(float('inf')) became "float('inf')", we'd lose the invariant that float(repr(x)) recovers x for all floats (including infinities and nans).

2. Since repr and str are currently identical for floats, this change would either end up modifying str too, or making str and repr different;  neither option is particularly palatable.  While I can see a case for the repr returning something eval-able, I think the str of an infinity should remain as "inf" or "-inf".

3. For consistency, you'd need to change the complex and Decimal outputs, too.

4. The current output of repr and str is directly parseable by most other languages.

So -1 from me.

(Changing type to 'enhancement'; we use 'behaviour' for bugs, and this isn't one. :-)

----------
type: behavior -> enhancement

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22951>
_______________________________________


More information about the Python-bugs-list mailing list