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 produces a different output on the second pass on VS Code #1491

Closed
sgleisner opened this issue Jun 12, 2020 · 4 comments
Closed

Black produces a different output on the second pass on VS Code #1491

sgleisner opened this issue Jun 12, 2020 · 4 comments
Labels
T: bug Something isn't working

Comments

@sgleisner
Copy link

sgleisner commented Jun 12, 2020

Some files produce an extra newline at the end when running black. On a second pass, that line gets removed. I have not been able to reproduce it outside VS Code.

To Reproduce:

  1. Download example.py and open it on a VS Code instance with the ms-python.python extension enabled (tested on v2020.5.86806, under VS Code 1.46.0. Possibly reproducible on other versions, too).

  2. Check that black is set as the default Python formatter on settings.json:

...
"python.formatting.provider": "black",
...

  1. Back in example.py's tab, open the command palette and select Format Document.
    It will leave 2 empty lines at the end of the file.

  2. Repeat step 3. It will remove one of the empty lines.

Expected behavior
Step 3 should result in an output that wouldn't change on a second pass of black (i.e., the output after step 4).

Environment:
Version: 19.10b0

Note: This is the version that black -- version outputs. However, I'm not 100% sure if ms-python.python is using that version.

  • OS and Python version:
    Linux, Python 3.6.9

Does this bug also happen on master?
I'm not sure (see note above)

Additional context
I believe this might be a duplicate of #1006, or it could be related to this VS Code issue. Since I'm not quite sure about that, I present this as a new issue, providing a simpler minimal reproducible example

@sgleisner sgleisner added the T: bug Something isn't working label Jun 12, 2020
@ichard26
Copy link
Collaborator

ichard26 commented Jun 12, 2020

Thanks for the bug report! These are the more subtle kinds of bugs that harder to spot. Although IMO it seems like a VS Code issue.

With a quick test, I cannot reproduce the bug running the same version of VS Code and the Python extension, but I'll try again harder later. A little note: version 19.10b0 is not master. It is in fact stable. Stable is the release branch that gets updated on every release. As I am writing, the stable branch is 115 commits behind master (we're getting close to being due for a release 😃 ).

@sgleisner
Copy link
Author

Oops! I totally confused stable with master. Fixed! Thanks @ichard26 for pointing it out.

Still, I'm not sure on how to check which version of black is using the ms-python.python extension.

I'll try to check if I can reproduce it in another environment. In the meantime, I suggest anybody trying to reproduce the issue to download the file instead of copying and pasting, just to be sure that autoformat on paste/save is not getting in the way of reproducing the problem.

@ichard26
Copy link
Collaborator

ichard26 commented Jul 19, 2020

Okay, so I can reproduce and, yes this is probably a duplicate of #1006. This is probably attributed to the bug report on the Visual Studio Code Python extension issue tracker.

@JelleZijlstra
Copy link
Collaborator

Can't reproduce this with Black by itself. It may be an editor bug as @ichard26 mentioned above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants