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
The following code can not be parsed/formatted by black:
{name_4: name_1forname_2insomethingiff'\\'if {}}
❯ .venv/bin/black -t py312 scripts/min_code.py
error: cannot format scripts/min_code.py: Cannot parse for target version Python 3.12: 1:53: {name_4: name_1 for name_2 in something if f'\\' if {}}
Oh no! 💥 💔 💥
1 file failed to reformat.
but it can be parsed by cpython.
❯ python3.12 scripts/min_code.py
Traceback (most recent call last):
File "/home/frank/projects/black/scripts/min_code.py", line 1, in <module>
{name_4: name_1 for name_2 in something if f'\\' if {}}
^^^^^^^^^
NameError: name 'something' is not defined
(this is not a parsing but an runtime error, which is ok)
I'm surprised that's valid python, that double if is certainly something. Looks to be the same issue as #4588, it parses if you make the f-string a normal string.
Describe the bug
The following code can not be parsed/formatted by black:
but it can be parsed by cpython.
(this is not a parsing but an runtime error, which is ok)
Environment
Additional context
The bug was found by pysource-codegen (see #3908)
The text was updated successfully, but these errors were encountered: