bpo-28146: Fix a confusing error message in str.format() (GH-24213)

Automerge-Triggered-By: GH:pitrou
(cherry picked from commit 4aeee0b47b)

Co-authored-by: Irit Katriel <iritkatriel@yahoo.com>
This commit is contained in:
Miss Islington (bot) 2021-05-13 14:24:49 -07:00 committed by GitHub
parent c4c3beb5ad
commit 2d780237d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 4 deletions

View file

@ -773,8 +773,14 @@ format_string_internal(PyObject *value, const InternalFormatSpec *format,
/* sign is not allowed on strings */
if (format->sign != '\0') {
PyErr_SetString(PyExc_ValueError,
"Sign not allowed in string format specifier");
if (format->sign == ' ') {
PyErr_SetString(PyExc_ValueError,
"Space not allowed in string format specifier");
}
else {
PyErr_SetString(PyExc_ValueError,
"Sign not allowed in string format specifier");
}
goto done;
}