-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Confusing error messages in str.format() #72333
Comments
For example: >>> '{:04}'.format('abc')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: '=' alignment not allowed in string format specifier There is no any '=' in the format string. >>> '{: }'.format('abc')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Sign not allowed in string format specifier There is no any sign ('+' or '-') in the format string. There also an inconsistency between the wording of "something not allowed in string format specifier" and: >>> '{:x}'.format('abc')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Unknown format code 'x' for object of type 'str'
>>> '{:xx}'.format('abc')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Invalid format specifier |
See also bpo-27772. The difference in the error messages is due to the first ones looking for specific invalid combinations (in this case things the string formatter does not understand), and the last one which is "I have no idea what you're asking for". |
My PR fixes the second case ('{: }') and Serhiy's PR on bpo-27772 fixes the first case ('{:04}'). |
It seems like this issue is entirely fixed now, closing. |
commit 4aeee0b
|
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: