Unhelpful error message
Thomas Nyberg
tomuxiong at gmx.com
Tue Jun 6 14:57:26 EDT 2017
On 06/06/2017 11:38 AM, Jon Ribbens wrote:
> On 2017-06-06, Peter Otten <__peter__ at web.de> wrote:
>> ...but not the empty string:
>>
>>>>> float("")
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in <module>
>> ValueError: could not convert string to float:
>>
>> Maybe there were some backward compatibility concerns that I lack the
>> fantasy to imagine.
>
> It's a little odd, PyFloat_FromString just calls:
>
> PyErr_Format(PyExc_ValueError,
> "could not convert string to float: %R", v);
>
> which should be appending the repr() of the argument to the error
> message, and there's no code I can see anywhere that would be
> special-casing the empty string and avoiding inserting "''".
>
If the string is empty, then the line:
if (end != last) {
does not evaluate to true, so you end up skipping the error you're
referring to and instead executing these lines:
else if (x == -1.0 && PyErr_Occurred()) {
return NULL;
}
So maybe the logic should be fixed here since the empty string is
basically taking a separate logical path than it philosophically should
(imo).
Cheers,
Thomas
More information about the Python-list
mailing list