-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
Improve errors messages in f-string syntax errors #91285
Comments
When an empty expression is provided in curly brackets inside an f-string we get Syntax Error: "f-string: empty expression not allowed". This is correct, however error with the same message is raised in the following cases: f"{!foo}", f"{!}", f"{:bar}", f"{=}", etc. I propose we raise an error with the message: "f-string: optional specifier '%c' must follow a non-empty expression. |
I'm not convinced this is an improvement. I don't think someone trying '!' in an f-string expression happens often enough to worry about that specific error message. And a generic "optional specifier" isn't great. If we're going to do this, it should reflect the actual thing that's present: a conversion specifier, a format specifier, or debug specifier. And "optional" doesn't add anything, since it's actually present in this string. I'll give it some more thought. I can't come up with an error message I actually like. The focus still needs to be on the empty expression. |
Understandable. In this case I can maybe propose something along the lines of "f-string: empty expression not allowed (Conversion specifier '!' can only follow non-empty expressions)", and so on for each of the specifiers. This way the original message is still present and we just add some more information. I'm open to any of your ideas. |
From a suggestion by @jelle on the python discord server: how about just "f-string: expression required before '!'"? |
I like the newest suggestion by @jelle better as well. |
I agree as well. I will change it to the new version :) Thanks for your input in this. |
Thanks, @macgors! |
Thanks for helping me with my very first python contribution! @eric.smith @lys.nikolaou |
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: