-
-
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
Signify that a SyntaxError comes from an fstring in the error message #85256
Comments
It's relatively easy to identify if a SyntaxError occurs when parsing an fstring expression or not. The idea is to slightly change the error message to start with "f-string: " when it does (in the same way in which SyntaxError messages are produced by the hand-written fstring parser). I have a working PR that produces the following: $ cat a.py
f'{a $ b}'
$ ./python.exe a.py
File "/Users/lysnikolaou/Repositories/cpython/a.py", line 1
(a $ b)
^
SyntaxError: f-string: invalid syntax Thoughts? |
I think it's a good idea. My only reservation would be: if the parsing of f-strings is moved into the parser, would it be possible to maintain the error new messages? |
Probably without a single change. |
Should we maybe backport this to 3.9 as well? |
I would say yes unless someone sees an obvious impediment |
AFAIK, we don't guarantee the stability of error messages, so I think backporting is fine. It's all the better that this is just prefixing something to an existing error message. |
The change broke the old parser in Python 3.9, I reopen the issue: AMD64 Arch Linux VintageParser 3.9: FAIL: test_format_specifier_expressions (test.test_fstring.TestCase) (str="f'{4:{/5}}'") |
Thanks, Victor! The fix is merged, so I'm closing this again. |
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: