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
Unhelpful error message with str.format() #49497
Comments
>>> "{0:f}".format(2.5)
'2.500000'
>>> "{0:f}".format("spam")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Unknown conversion type f The error message should mention the type of the argument that doesn't |
I agree. I'm not sure on backporting this. I'll work on a patch. |
Seems like a reasonable backport. |
I've gone back and read PEP-3101. To use its terminology, I think the I'm not sure where I got the original wording "conversion type". It's It's unfortunate that "type" is used in the PEP and the online docs for Any suggestions for clearer wording? |
The attached patch (against trunk) changes the message. However, it has at least one unintended consequence. If you have an >>> '{0:^10}'.format(0j)
' 0j '
>>> '{0:^10x}'.format(0j)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Unknown presentation type x for str
>>> I'm calling format on an complex number, but the error says "str". The |
Use "formatting code" rather than "presentation type"? |
With this patch, I changed it to "format code", and made it more in line I'm okay with "format code" or "formatting code", but if we do use >>> '{0:x}'.format('')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Unknown format code 'x' for object of type 'str'
>>> |
I'm getting ready to commit this. Does it need a test? I poked around |
Looks good to me. I don't think you need to write a specific test for this. |
Committed in: |
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: