mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-95605: Fix float(s)
error message when s
contains only whitespace (GH-95665) (GH-95858)
This PR fixes the error message from float(s) in the case where s contains only whitespace.
(cherry picked from commit 97e9cfa75a
)
Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
This commit is contained in:
parent
731732aa8b
commit
3ea9ba6478
3 changed files with 14 additions and 1 deletions
|
@ -162,11 +162,18 @@ float_from_string_inner(const char *s, Py_ssize_t len, void *obj)
|
|||
double x;
|
||||
const char *end;
|
||||
const char *last = s + len;
|
||||
/* strip space */
|
||||
/* strip leading whitespace */
|
||||
while (s < last && Py_ISSPACE(*s)) {
|
||||
s++;
|
||||
}
|
||||
if (s == last) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"could not convert string to float: "
|
||||
"%R", obj);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* strip trailing whitespace */
|
||||
while (s < last - 1 && Py_ISSPACE(last[-1])) {
|
||||
last--;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue