Message122612
>>> 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: |
|
Date |
User |
Action |
Args |
2010-11-28 03:22:26 | belopolsky | set | recipients:
+ belopolsky, mark.dickinson, vstinner, ezio.melotti |
2010-11-28 03:22:26 | belopolsky | set | messageid: <1290914546.61.0.639677577533.issue10557@psf.upfronthosting.co.za> |
2010-11-28 03:22:23 | belopolsky | link | issue10557 messages |
2010-11-28 03:22:23 | belopolsky | create | |
|