You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Organize imports conflicts with Black formatting #6933
I think I know whats happening, not easy to replicate.
We have two formatters, one formats the code first, then another comes in and formats the code.
At this stage I'd say we'd need a decision on what needs to be done.
Basically its a conflict of using two formatters (sort imports is a type of a formatter).
@cmcarey
Thanks for reporting this issue.
Yes, theres a conflict. The reason is simple we are using two formatters when saving changes to a file. The results vary based on which formatter completes first. I.e. if black formats first, then you see one result, then isort formats the imports and changes the imports and you see another set of changes.
As you keep hitting save both trip on one another.
Ideally the solution is to use just one and not two. At the end of the day black will re-format the entire file.
I've left this issue open so we can decide whether such a configuration is supported (using sort imports and a formatter together).
Thanks for reporting this issue.
Yes, theres a conflict. The reason is simple we are using two formatters when saving changes to a file. The results vary based on which formatter completes first. I.e. if black formats first, then you see one result, then isort formats the imports and changes the imports and you see another set of changes.
As you keep hitting save both trip on one another.
Ideally the solution is to use just one and not two. At the end of the day black will re-format the entire file.
I've left this issue open so we can decide whether such a configuration is supported (using sort imports and a formatter together).
I see, thank you. I use isort in combination with black as it offers features that black alone does not.
black, by design, does not touch the order of the imports as this can change code functionality. I don't care about that, hence using isort.
As to being easy to replicate, if you copy the short example I used, it should demonstrate the issue (I've verified myself on a few different machines using vscode-python + latest black).
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)
Activity
DonJayamanne commentedon Aug 12, 2019
I think I know whats happening, not easy to replicate.
We have two formatters, one formats the code first, then another comes in and formats the code.
At this stage I'd say we'd need a decision on what needs to be done.
Basically its a conflict of using two formatters (sort imports is a type of a formatter).
DonJayamanne commentedon Aug 12, 2019
@cmcarey
Thanks for reporting this issue.
Yes, theres a conflict. The reason is simple we are using two formatters when saving changes to a file. The results vary based on which formatter completes first. I.e. if black formats first, then you see one result, then isort formats the imports and changes the imports and you see another set of changes.
As you keep hitting save both trip on one another.
Ideally the solution is to use just one and not two. At the end of the day
blackwill re-format the entire file.I've left this issue open so we can decide whether such a configuration is supported (using sort imports and a formatter together).
chancecarey commentedon Aug 12, 2019
Don Jayamanne (@DonJayamanne)
I see, thank you. I use
isortin combination withblackas it offers features thatblackalone does not.black, by design, does not touch the order of the imports as this can change code functionality. I don't care about that, hence usingisort.As to being easy to replicate, if you copy the short example I used, it should demonstrate the issue (I've verified myself on a few different machines using vscode-python + latest black).
max-sixty commentedon Aug 13, 2019
Are your isort setting consistent with black? There are a specific set of black settings that don't conflict
max-sixty commentedon Aug 14, 2019
I had this issue but updated the
isortargs in vscode settings to match those consistent with black, and that stopped the flickering (but not ideal - ideally it would use those insetup.cfg)ovidner commentedon Oct 17, 2019
A copy-and-paste-able version of Maximilian Roos (@max-sixty)'s workaround:
(add this to the
settings.jsonof your own choice)EDIT: Changed to the exact arguments suggested in Black's docs
luabud commentedon Oct 29, 2019
Closing in favour of microsoft/vscode#83586.