[New-bugs-announce] [issue10557] Malformed error message from float()

Alexander Belopolsky report at bugs.python.org
Sun Nov 28 04:22:26 CET 2010


New submission from Alexander Belopolsky <belopolsky at users.sourceforge.net>:

>>> float('½')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: could not convert string to float: �

>>> float('42½')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError

With the attached patch, float-error.diff


>>> float('½')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for float(): ½
>>> float('42½')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for float(): 42½

Note that the proposed patch also has an effect of disallowing non-ascii digits in float() constructor.

Before the patch:

>>> float('١٢٣٤.٥٦')
1234.56

After the patch:

>>> float('١٢٣٤.٥٦')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: could not convert string to float: ١٢٣٤.٥٦

I am not sure, whether support for non-ascii digits in float() constructor is worth maintaining.  (Anyone knows whether Arabic numbers are written right to left or left to right?  What is the proper decimal point character?)

Also, I don't think users expect UnicodeEncodeError from float() or int().

Before the patch:

>>> float('\uffff')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'decimal' codec can't encode character '\uffff' in position 0: invalid decimal Unicode string


After the patch:

>>> float('\uffff')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: could not convert string to float: ￿

----------
components: Interpreter Core
files: float-error.diff
keywords: patch
messages: 122612
nosy: belopolsky, ezio.melotti, haypo, mark.dickinson
priority: normal
severity: normal
stage: unit test needed
status: open
title: Malformed error message from float()
type: behavior
versions: Python 3.2
Added file: http://bugs.python.org/file19848/float-error.diff

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


More information about the New-bugs-announce mailing list