-
-
Notifications
You must be signed in to change notification settings - Fork 32k
Unexpected whitespace handling in f-string !r #93283
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
Comments
cc @pablogsal b/c 2022 PSL f-string grammar |
cc @ericvsmith who continues to gather feefback |
The space in the statements with a syntax error above is not part of the expression, it's part of the conversion specifier. I do not want to weaken the parsing here, and I do not consider this a bug. I suppose we could improve the error message, and a quick search doesn't show a test for this. There is a test for a space in |
Marking as a feature request for a better error message or better documentation, given a core developer has noted this is not a bug. A |
A side note on multi-line f-strings. f"""{
None
}"""
c = f"""{
None
!r}""" but not this: d = f"""{
None!r
}""" I feel that the developer experience is subpar here. |
I can assure you that conversion specifiers were not an afterthought. They come from PEP 3101 (16 years ago), and were present from the beginning. If the error message were "Unknown conversion specifier 'r\n'", would that not make it clear enough what the problem is? |
I apologize, I must have misread the spec and I was under the impression that |
The spec has no preference: either way works. It’s just a style thing. |
Bug report
The handling of whitespace around the argument in literal string interpolation (f-string) is unexpected when a conversion specifier (e.g. !r) is applied.
Consider
PEP-498 states:
I suppose that the text above may be technically accurate, but is misleading to common folk:
In the example above,
None
is enclosed in parentheses(None)
but notNone!r
.There are no mentions of whitespace in the rest of the PEP.
Formal reproducer:
Your environment
The text was updated successfully, but these errors were encountered: