question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Organize imports conflicts with Black formatting

See original GitHub issue

Environment data

  • VS Code version: 1.37.0
  • Extension version (available under the Extensions sidebar): 2019.8.29288
  • OS and version: Windows 10 Enterprise, 10.0.17763 Build 17763
  • Python version: 3.7.4
  • Type of virtual environment used: Poetry/venv
  • Relevant/affected Python packages and their versions: black: 19.3-beta.0
  • Jedi or Language Server: Language server

Expected behaviour

Saving a file should not toggle between black-formatted and isort-formatted.

Actual behaviour

Saving a file once results in black-formatted, then saving it again results in isort-formatted, saving that results in black-formatted, and so on.

Steps to reproduce:

  1. Have Black installed
  2. Set config options as such:
{
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
    "source.organizeImports": true
  }
}
  1. Create a python file with the following contents:
from something import (
    aaaaa,
    bbbbb,
    ccccc,
    ddddd,
    eeeee,
    fffff,
    ggggg,
    hhhhh,
    iiiii,
    jjjjj,
    kkkkk,
)
  1. Save the file multiple times and watch it dance

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
max-sixtycommented, Aug 14, 2019

I had this issue but updated the isort args in vscode settings to match those consistent with black, and that stopped the flickering (but not ideal - ideally it would use those in setup.cfg)

0reactions
luabudcommented, Oct 29, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

Python & VS Code: make Black and organize imports work ...
I use Black to format my Python code, and I tell VS Code to organise imports on save. Here's the relevant bit of...
Read more >
Using Black with other tools - Black 22.12.0 documentation
Some of them need a bit of tweaking to resolve the conflicts. Listed below are Black ... isort helps to sort and format...
Read more >
Imports are incorrectly sorted and/or formatted | VS Code
My guess is your linter is complaining about unused imports. Hover over the red underscored word and see what the message is. –...
Read more >
Making isort compatible with black - A code to remember
Both isort and black are a must have in my python life, but with their default settings, I will get different imports formats....
Read more >
How to automate Python code formatting | by AlexV - Medium
pipenv run pip install black. Below I have created a file that I would like to format: import os, sysfrom file_to_be_imported import ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found