Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Kami opened this issue Mar 19, 2019 · 8 comments
Closed

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

Kami opened this issue Mar 19, 2019 · 8 comments

Comments

@Kami
Copy link

Kami commented Mar 19, 2019

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

@JelleZijlstra
Copy link
Collaborator

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

@runekaagaard
Copy link

I tested it against cea13f4 and it works.

@chingc
Copy link

chingc commented Jun 27, 2019

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.

@chingc
Copy link

chingc commented Jun 27, 2019

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

@jace
Copy link

jace commented Jul 15, 2019

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

@truh
Copy link

truh commented Jul 15, 2019

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.

@BrianChristie
Copy link

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

@hugovk
Copy link
Contributor

hugovk commented Oct 21, 2019

Yes, there'll be a new release out soonish, see #988.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants