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 inserts unnecessary whitespace around print() with target_version = py27 #752

Closed
rouge8 opened this issue Mar 14, 2019 · 7 comments
Closed

Comments

@rouge8
Copy link
Contributor

rouge8 commented Mar 14, 2019

black is adding whitespace between print and ( with --target-version py27.

Test file:

from __future__ import print_function

print("hello world")

Result:

$ black t.py --target-version py27 --diff
--- t.py	2019-03-14 22:09:34.902887 +0000
+++ t.py	2019-03-14 22:10:21.022372 +0000
@@ -1,4 +1,4 @@
 from __future__ import print_function

-print("hello world")
+print ("hello world")

reformatted t.py
All done! ✨ 🍰 ✨
1 file reformatted.

Operating system: OS X
Python version: 3.7.2
Black version: 19.3b0
Does also happen on master: yes

@ambv
Copy link
Collaborator

ambv commented Mar 14, 2019

That's a bug, it's trying the non-print function grammar first. @JelleZijlstra :-)

@vbukhonov
Copy link

@ambv @JelleZijlstra
Hello. Sorry, but I am still facing this bug under python 3.

@chebee7i
Copy link

Can we get a release out for this? Trying to use the current release on 2.x is producing ugly code with these extra spaces.

@tommyjcarpenter
Copy link

tommyjcarpenter commented Jun 19, 2020

Has this been switched to the stable branch? I am (per the vim instructions) using the latest stable version of black and I still hit this issue. I commented here: #988

It seems like the commit should be there: d6db1c1

However I am hitting this issue today (june 2020) with the latest stable black while editing python 2.7 code using let g:black_target_version=27 in vimrc

@vinyasmusic
Copy link

Facing this issue with Python 3.6
Black formats this piece of code print("cacheops.{} for {}".format(event, sender)) to print ("cacheops.{} for {}".format(event, sender))
And then the flake8 checker flags this under E211

@tommyjcarpenter
Copy link

I vote to reopen this issue. I do not think this is closed or resolved.

@cg-cnu
Copy link

cg-cnu commented Dec 6, 2021

Ran into this on V 19.10b0. Looks like the spaces after the print () are added if there is a print statement (print "test") in the code. Totally my mistake but thought it might save others some hair.

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

7 participants