"EOF in multi-line string" on string containing same quote nested in f-string
Describe the bug
black cannot format this type of code: f"{'\''}"
$ black foo.py
error: cannot format foo.py: Cannot parse: 1:3: EOF in multi-line string
Oh no! 💥 💔 💥
1 file failed to reformat.
I was thinking that it might be the same bug as https://github.com/psf/black/issues/4334, but the example in that issue (f'{'a'}') doesn't produce an error in black 24.4.2 anymore, and Python 3.12.2 accepts the above code:
import ast
from pathlib import Path
print(f"{'a'}")
print(ast.parse(Path(__file__).read_text()))
$ python3 example.py
a
<ast.Module object at 0x1014a9410>
To Reproduce
Expected behavior
I have no opinion on how this should be formatted. Leaving this code as it is would be fine.
Environment
$ black --version
black, 24.4.2 (compiled: yes)
Python (CPython) 3.12.2
macOS 12.7.4 (21H1123)
I guess it because backslash() aren't allowed in f-string brackets. You can use the double backslash if you want it on the string
I guess it because backslash() aren't allowed in f-string brackets. You can use the double backslash if you want it on the string
They are allowed since Python 3.12: https://godbolt.org/z/9zGsezrEh