You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> [cannot format file.py: INTERNAL ERROR: ...](error: cannot format: simplex\utils.py: INTERNAL ERROR: Black produced invalid code: f-string: expecting '}' (<unknown>, line 6). Please report a bug on https://github.com/psf/black/issues. This invalid output might be helpful: Temp\blk_k8cady1s.log)
SUBSCRIPTS = {i: chr(0x2080 + i) for i in range(10)}
def cant_format(row):
return " + ".join(
[
f"{coefficient if coefficient != 1 else ''}x{''.join(SUBSCRIPTS[int(digit)] for digit in str(i+1))}"
for i, coefficient in enumerate(row)
]
)
print(cant_format([1, 2]))
Black fails to format complicated f-string
To Reproduce
Black Playground
And run it with these arguments:
$ black simplex\utils.py
The resulting error is:
Log File Output
The error is due to the
}
being carried to the next line. I would expect the whole f-expression to be on one line.If single quotes are used in the first statement after the else, then black correctly formats this i.e. the below works fine.
Expected behaviour
Black should correctly format the code, I would expect something very similar to the following:
Environment
>black --version black, 23.12.1 (compiled: yes) Python (CPython) 3.12.0
The text was updated successfully, but these errors were encountered: