Skip to content

Include the opening brace's line in multiline f-string errors #157778

Description

@pablogsal

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions