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 produced invalid code on pass 1 when parsing an assert with walrus operator.
To Reproduce
create a file test.py
def a():
assert (x := 1 == 1)
Run black test.py
Expected behavior
The output file should be the same as the input file.
Environment
Version: master/21.4b0
OS and Python version: macOS Big Sur 11.2.3 and Python3.8
Does this bug also happen on master?
Yes
Additional context
This is the log output:
❯ poetry run black test.py
error: cannot format test.py: INTERNAL ERROR: Black produced invalid code on pass 1: The requested source code has invalid Python 3 syntax.
If you are trying to format Python 2 files please reinstall Black with the 'python2' extra: `python3 -m pip install black[python2]`.. Please report a bug on https://github.com/psf/black/issues. This invalid output might be helpful: /var/folders/xg/0x59hpln7h70f114ljbbjq400000gp/T/blk_es7z7u5g.log
Oh no! 💥 💔 💥
1 file failed to reformat.
❯ cat /var/folders/xg/0x59hpln7h70f114ljbbjq400000gp/T/blk_es7z7u5g.log
File "/Users/alessandroberlati/aberlathy/test_black/.venv/lib/python3.8/site-packages/black/__init__.py", line 6508, in assert_equivalent
dst_ast = parse_ast(dst)
File "/Users/alessandroberlati/aberlathy/test_black/.venv/lib/python3.8/site-packages/black/__init__.py", line 6404, in parse_ast
raise SyntaxError(
def a():
assert x := 1 == 1
It's removing the parenthesis after the assert but that's not valid python.
The text was updated successfully, but these errors were encountered:
Describe the bug
Black produced invalid code on pass 1
when parsing an assert with walrus operator.To Reproduce
test.py
black test.py
Expected behavior
The output file should be the same as the input file.
Environment
Does this bug also happen on master?
Yes
Additional context
This is the log output:
It's removing the parenthesis after the assert but that's not valid python.
The text was updated successfully, but these errors were encountered: