-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-93283: Improve error message for f-string with invalid conversion character #93349
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
gh-93283: Improve error message for f-string with invalid conversion character #93349
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What error should be for f'{3!g'
? "invalid conversion character" or "expecting '}'"?
What error should be for f'{3!:'
? "missed conversion character" or "expecting '}'"?
Personally, I'd expect A |
Btw we are just working on this in the "porting f-strings to the grammar" project in case you have time to help @serhiy-storchaka |
It is easy for |
"expected 's', 'r', or 'a'" % conv, | ||
["f'{3!" + conv + "}'"]) | ||
|
||
self.assertAllRaise(SyntaxError, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somewhere we should probably add whitespace both before and after the conversion character: "s ", " s", " s ". It looks like that got dropped.
The idea is good at first glance, I thought about it, but it looks too complicated. The main problem is that the closing quote must match the opening one. It can be solved, but it needs significant effort. There are easier and more important problems. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
#93283.