Skip to content

Cannot parse multiline f-string containing multiline string #4337

@tarper24

Description

@tarper24

Describe the bug

Black fails to parse a file containing a multiline f-string which contains a multiline string within curly braces

To Reproduce

I created this MRC

f"""{'''
'''}"""

And just run black on the file:

$ black file.py

The resulting error is:

error: cannot format file.py: Cannot parse: 1:5: f"""{'''

Expected behavior

Successfully parse as it did in version <= 24.4.0

Environment

  • Black's version: 24.4.2
  • OS and Python version: Windows 11, Python 3.10, 3.11, 3.12

Additional context

Related to #4329

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