Skip to content

Black fails to format triple quoted string with a new line in f-string. #4375

@apes0

Description

@apes0

Describe the bug

Black fails to format an f-string, containing a triple quoted string, that has a new line in it.

To Reproduce

For example, take this code:

a = f'''{"""
"""}'''

And run it with these arguments:

$ black file.py

The resulting error is:

error: cannot format a.py: Cannot parse: 1:9: a = f'''{"""

Expected behavior

The file should be formatted. I am not sure how this should get formatted though. The code is valid for both versions of python that i tested.

Environment

  • Black's version: 24.4.2
  • OS and Python version: Ubuntu 24.04 and Python 3.12/3.10 (fails on both)

P.S.: This seems somewhat similar to #4350?

Metadata

Metadata

Assignees

No one assigned

    Labels

    T: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions