Include the opening brace's line in multiline f-string errors
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
An unclosed f-string replacement field can report an error on a later line, making the opening brace hard to find:
var = "abc"
a = f""" {var} extern "C" { """
b = """ string """
File "script.py", line 3
b = """ string """
^
SyntaxError: f-string: expecting '}'
The quotes after the second { start a string inside the replacement field. That string ends on line 3, and the final quotes start another string that is never closed.
The error should include the line number of the opening brace:
SyntaxError: f-string: expecting '}' to close '{' on line 2
The same problem affects t-strings. Valid strings inside replacement fields should continue to work.
Linked PRs
- gh-157779
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided multiline f-string reproducer and compare its diagnostic with the expected message. Check the corresponding t-string case and confirm that valid strings inside replacement fields still work. Done means both affected error messages identify the opening brace's line without regressing valid strings; a linked pull request is already listed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100