Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Black 23.11 cannot parse 3.12 enhanced f-strings #4088

Closed
smcclure17 opened this issue Dec 6, 2023 · 1 comment
Closed

Black 23.11 cannot parse 3.12 enhanced f-strings #4088

smcclure17 opened this issue Dec 6, 2023 · 1 comment
Labels
T: bug Something isn't working

Comments

@smcclure17
Copy link

Describe the bug

PEP 701 (Python 3.12) introduced the ability to reuse the same quote type (e.g. ") within f-strings. Black is unable to parse this new structure, causing the formatter to fail.

To Reproduce

For example, take this code:

name = "cool_guy"
works = f"hello {cool_guy.replace('_', ' ')}"
broken = f"hello {cool_guy.replace("_", " ")}"  # now possible in Python 3.12

And run it with these arguments:

$ black file.py

The resulting error is:

Cannot parse: 3:36: broken = f"hello {cool_guy.replace("_", " ")}"
Oh no! 💥 💔 💥
1 file failed to reformat.

Expected behavior

Expect Black to succeed and properly format the file.

Environment

  • Black's version: 23.11.0
  • OS and Python version: MacOS/3.12.0

Additional context

None

@smcclure17 smcclure17 added the T: bug Something isn't working label Dec 6, 2023
@hauntsaninja
Copy link
Collaborator

Duplicate of #3746

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants