From 4aeee0b47b3a2b604bbac37040320ffc88c291f2 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Thu, 13 May 2021 21:55:55 +0100 Subject: bpo-28146: Fix a confusing error message in str.format() (GH-24213) Automerge-Triggered-By: GH:pitrou --- Python/formatter_unicode.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'Python') diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c index 5ccf9d303e..7b5a7bd04e 100644 --- a/Python/formatter_unicode.c +++ b/Python/formatter_unicode.c @@ -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; } -- cgit v1.2.1