black fails on print function when using Python 2.7 as target version

Created on 19 Mar 2019  路  8Comments  路  Source: psf/black

When running black on Python file which uses from __future__ import print_function statement with Python 2.7 target, it fails with the following error:

$ black --target-version py27 test.py 
error: cannot format test.py: Cannot parse: 5:21: print("foo bar", file=sys.stderr)
All done! 馃挜 馃挃 馃挜
1 file failed to reformat.
$ cat test.py
from __future__ import print_function

import sys

print("foo bar", file=sys.stderr)

Since from __future__ import print_function statement is used, I don't think it should fail in this scenario.

Environment information:

Operating system: Ubuntu Xenial
Python version: Python 3.6.7
Black version: black, version 19.3b0

Most helpful comment

I tested it against cea13f498418784e22f8fbd78db3f9240a2bad11 and it works.

All 8 comments

I believe this is fixed in master, can you check?

I tested it against cea13f498418784e22f8fbd78db3f9240a2bad11 and it works.

Will there be a new release soon that includes this fix? I'm in the process of migrating a codebase to python 3 and would prefer not to disable black.

Nevermind, I was able to use the fixed version by updating my pre-commit config. 馃帀

I just ran into this problem using pre-commit with the stable branch. What release are you all using? Should I switch to master?

I also just ran into this problem. This is my pyproject.toml

[tool.black]
target_version = ['py27', 'py36']

I use black version19.3b0 which I just installed from pip.

Works fine after downgrading with pip install black==18.9b0.

Also ran into this issue. Is there a new release planned soon?

Yes, there'll be a new release out soonish, see https://github.com/psf/black/issues/988.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bofm picture bofm  路  72Comments

underyx picture underyx  路  22Comments

devxpy picture devxpy  路  70Comments

sfermigier picture sfermigier  路  43Comments

adamehirsch picture adamehirsch  路  48Comments