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
Black crashes when trying to format code containing a string inside an f-string that uses the same type of quotes. This is valid syntax as of python 3.12.
To Reproduce
For example, take this code:
#! /usr/bin/env python3print(f"{"a"}")
And run it with these arguments:
$ black --verbose --target-version py312 source.py
The resulting error is:
Identified `/` as project root containing a file system root.
Found input source: "net/home/h02/jfrost/blacktest/source.py"
Traceback (most recent call last):
File "/data/users/jfrost/conda/envs/cset-dev/lib/python3.12/site-packages/black/__init__.py", line 837, in reformat_one
if changed is not Changed.CACHED and format_file_in_place(
^^^^^^^^^^^^^^^^^^^^^
File "/data/users/jfrost/conda/envs/cset-dev/lib/python3.12/site-packages/black/__init__.py", line 879, in format_file_in_place
dst_contents = format_file_contents(
^^^^^^^^^^^^^^^^^^^^^
File "/data/users/jfrost/conda/envs/cset-dev/lib/python3.12/site-packages/black/__init__.py", line 1005, in format_file_contents
dst_contents = format_str(src_contents, mode=mode, lines=lines)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/users/jfrost/conda/envs/cset-dev/lib/python3.12/site-packages/black/__init__.py", line 1156, in format_str
dst_contents = _format_str_once(src_contents, mode=mode, lines=lines)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/users/jfrost/conda/envs/cset-dev/lib/python3.12/site-packages/black/__init__.py", line 1170, in _format_str_once
src_node = lib2to3_parse(src_contents.lstrip(), mode.target_versions)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/users/jfrost/conda/envs/cset-dev/lib/python3.12/site-packages/black/parsing.py", line 89, in lib2to3_parse
raise exc from None
black.parsing.InvalidInput: Cannot parse: 3:10: print(f"{"a"}")
error: cannot format source.py: Cannot parse: 3:10: print(f"{"a"}")
Oh no! 💥 💔 💥
1 file failed to reformat.
Expected behavior
The code is successfully formatted.
Environment
Black's version: black, 23.11.0 (compiled: no)
OS and Python version: Linux (RHEL7), Python 3.12.0
Additional context
The text was updated successfully, but these errors were encountered:
Describe the bug
Black crashes when trying to format code containing a string inside an f-string that uses the same type of quotes. This is valid syntax as of python 3.12.
To Reproduce
For example, take this code:
And run it with these arguments:
The resulting error is:
Expected behavior
The code is successfully formatted.
Environment
Additional context
The text was updated successfully, but these errors were encountered: