Black: Black fails with "AST error message: invalid syntax" if using the walrus operator in parenthesis

Created on 6 Feb 2020  ·  2Comments  ·  Source: psf/black

Describe the bug Black cannot format code that uses the walrus operator, := , in parentheses

To Reproduce Steps to reproduce the behavior:

  1. Take this file:

if (blah := 4):
    print(666)
  1. Run _Black_ (v19.10b0) on it with default arguments
  2. It should produce the following error: error: cannot format example.py: cannot use --safe with this file; failed to parse source file. AST error message: invalid syntax (<unknown>, line 1)

Expected behavior It should format the file and not throw an error

Environment (please complete the following information):

  • Version: 19.10b0
  • OS and Python version: Linux Mint 19.3, python 3.8.0

Does this bug also happen on master? No

bug

Most helpful comment

I can't repro this either locally or on https://black.now.sh so there's something likely with your environment. I would check what version of python Black is running with. You'd get this message if you're running it with something <3.8

All 2 comments

I can't repro this either locally or on https://black.now.sh so there's something likely with your environment. I would check what version of python Black is running with. You'd get this message if you're running it with something <3.8

I can't reproduce this either. Tested with black 19.10b0 on Mint 19 and Python 3.8.1

✗ cat 1262.py
if (blah := 4):
print(666)

✗ black .
reformatted 1262.py
All done! ✨ 🍰 ✨
1 file reformatted, 17 files left unchanged.

✗ cat 1262.py
if (blah := 4) :
print(666)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kissgyorgy picture kissgyorgy  ·  3Comments

J0 picture J0  ·  3Comments

JelleZijlstra picture JelleZijlstra  ·  3Comments

craigmac picture craigmac  ·  3Comments

dimaqq picture dimaqq  ·  3Comments