Author belopolsky
Recipients belopolsky, ezio.melotti, mark.dickinson, vstinner
Date 2010-11-28.03:22:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1290914546.61.0.639677577533.issue10557@psf.upfronthosting.co.za>
In-reply-to
Content
>>> 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: ￿
History
Date User Action Args
2010-11-28 03:22:26belopolskysetrecipients: + belopolsky, mark.dickinson, vstinner, ezio.melotti
2010-11-28 03:22:26belopolskysetmessageid: <1290914546.61.0.639677577533.issue10557@psf.upfronthosting.co.za>
2010-11-28 03:22:23belopolskylinkissue10557 messages
2010-11-28 03:22:23belopolskycreate