Skip to content

Failing to parse single-quote f-string with backslash inside it #2348

Closed
@whinee

Description

Describe the bug

The formatter is failing to parse single quote f-string as it cannot include a backslash inside it.

To Reproduce

  1. Take this test.py containing:
b = "example1"
sts = "example2"
f"\"{b}\"{' ' * (long-len(b)+1)}: \"{sts}\",\n"
  1. Run black without arguments.
  2. See error -->
  File "/var/task/black/__init__.py", line 986, in assert_equivalent
    dst_ast = parse_ast(dst)
  File "/var/task/black/parsing.py", line 125, in parse_ast
    raise SyntaxError(
f'"{b}"{\' \' * (long-len(b)+1)}: "{sts}",\n'

Expected behavior
The formatter is expected to throw the said error and fail to format the said file.

Environment (please complete the following information):

  • Version: [main]
  • OS and Python version: [Linux/Python 3.9.5]

Does this bug also happen on main?
Yes

Activity

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

Metadata

Assignees

Labels

C: invalid codeBlack destroyed a valid Python fileF: stringsRelated to our handling of stringsT: bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions