Replace weird error message?

Terry Reedy tjreedy at udel.edu
Wed Mar 16 16:27:12 EDT 2016


On 3/16/2016 2:53 PM, Ben Finney wrote:
> "the.gerenuk--- via Python-list" <python-list at python.org> writes:
>
>> The following error message, makes it a bit hard to understand what went wrong
>>
>>>>> "{:02}".format("1")
>> Traceback (most recent call last):
>>    File "<stdin>", line 1, in <module>
>> ValueError: '=' alignment not allowed in string format specifier
>
> Meaning that the ‘str.format’ mini-language parser has decided on the
> alignment specifier “=”. It's chosen that because:
>
>      Preceding the width field by a zero ('0') character enables
>      sign-aware zero-padding for numeric types. This is equivalent to a
>      fill character of '0' with an alignment type of '='.
>
>      <URL:https://docs.python.org/3/library/string.html#formatspec>
>
> Nothing in the error message indicates why “'=' alignment” is relevant,
> and it does not appear in the code.
>
>> Do you think some better error message should be used?
>
> Yes, I think that error message needs to be improved. Please file a bug
> report in Python's issue tracker <URL:https://bugs.python.org/>.

There already is a closed doc issue, which I am going to reopen to 
further revise the doc. https://bugs.python.org/issue15660

>> For example a hint that "0" does work for the given argument.
>
> I suggest: “zero-padding only allowed for numeric types, not 'str'”.

As someone else said, not true.

The problem with changing the exception message is that the formatter 
does not know at the point of the exception whether the alignment was 
set to '=' explicitly by the user or implicitly by the use of '0' fill.

-- 
Terry Jan Reedy





More information about the Python-list mailing list