Skip to content

--preview flag produces INTERNAL ERROR: f-string expression part cannot include a backslash #3506

@oleksandr-terentiev

Description

@oleksandr-terentiev

Black v23.1a1

Playground link

Options

--line-length=80
--safe
--preview

Input

my_dict = {"foo": "bar"}
s= f'Lorem Ipsum is simply dummy text of the printing and typesetting industry:\'{my_dict["foo"]}\''

Output

INTERNAL ERROR: Black produced invalid code: f-string expression part cannot include a backslash (<unknown>, line 5). Please report a bug on https://github.com/psf/black/issues.  This invalid output might be helpful: /tmp/blk_5qbr6zhy.log

  File "src/black/__init__.py", line 1324, in assert_equivalent
  File "src/black/parsing.py", line 183, in parse_ast
my_dict = {"foo": "bar"}
s = (
    "Lorem Ipsum is simply dummy text of the printing and typesetting"
    f" industry:'{my_dict[\"foo\"]}'"
)

Expected

my_dict = {"foo": "bar"}
s = (
    "Lorem Ipsum is simply dummy text of the printing and typesetting"
    f" industry:'{my_dict['foo']}'"
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: preview styleIssues with the preview and unstable style. Add the name of the responsible feature in the title.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions