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

INTERNAL ERROR: Black produced invalid code: f-string: expecting '}' #4284

Closed
nernst opened this issue Mar 18, 2024 · 1 comment
Closed

INTERNAL ERROR: Black produced invalid code: f-string: expecting '}' #4284

nernst opened this issue Mar 18, 2024 · 1 comment
Labels
T: bug Something isn't working

Comments

@nernst
Copy link

nernst commented Mar 18, 2024

Describe the bug

Black reports an internal error with certain long f-strings as it tries to break the line in a syntactically invalid place.

To Reproduce

For example, take this code:

something = []

test_string = f"this is a really string that will be line broken at 120 chars that contains an interpolated join {",".join(something)}"

And run it with these arguments:

$ black file.py -l 120 --target-version py312

The resulting error is:

error: cannot format example.py: INTERNAL ERROR: Black produced invalid code: f-string: expecting '}' (<unknown>, line 4). Please report a bug on https://github.com/psf/black/issues.  This invalid output might be helpful: /tmp/blk_9n5hjqrh.log

Oh no! 💥 💔 💥
1 file failed to reformat.

Expected behavior

The line should not be formatted/line should not be broken in an invalid position

Environment

  • Black's version: 24.3.0 (compiled: yes)
  • OS and Python version: Linux/CPython 3.12.2

Additional context

A work-around for this case is to change the ",".join(...) to ','.join(...).

@nernst nernst added the T: bug Something isn't working label Mar 18, 2024
@JelleZijlstra
Copy link
Collaborator

Duplicate of #3746

@JelleZijlstra JelleZijlstra marked this as a duplicate of #3746 Mar 18, 2024
@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale Mar 18, 2024
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