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.
Operating system: Ubuntu Xenial
Python version: Python 3.6.7
Black version: black, version 19.3b0
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.
Most helpful comment
I tested it against cea13f498418784e22f8fbd78db3f9240a2bad11 and it works.