Skip to content

Auto formatting of document+imports racing condition? #2301

@gandalfsaxe

Description

@gandalfsaxe

Issue Type: Bug

I use the following settings:

  "[python]": {
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
    "source.organizeImports": true
    },
  },
  "python.formatting.provider": "black"

However the imports formatting is very inconsistent. Sometimes it follows black, and most times it doesn't. Any multi-line imports where each imported variable/function should be on it's own line (according to black) often isn't.

If I run Format Document, it formats the imports according to black (one per line):
image

If I run Organize Imports, it puts everything on as few lines as possible (violates black):
image

And worst of all, it seems like VSCode is alternating between these two outcomes

  1. non-black style
  2. non-black style for half a second, then black style.

Since it sometimes work, it seems as if there is a racing condition between the Format Document command and Organize Imports command when both are auto enabled on save in settings. The right thing to do would seem to first run the ordinary import formatting, then run any custom formatting provider afterwards.

Since this looks like a bug / conflict between the "Format Document" and "Organize Imports" commands., which are both build-in, I think this is a VSCode problem, not vscode-python extension problem.

VS Code version: Code - Insiders 1.26.0-insider (573d538, 2018-08-01T05:17:54.216Z)
OS version: Windows_NT x64 10.0.15063

System Info
Item Value
CPUs Intel(R) Core(TM) i7-6700T CPU @ 2.80GHz (8 x 2808)
GPU Status 2d_canvas: enabled
checker_imaging: disabled_off
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: enabled
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
Memory (System) 15.88GB (7.09GB free)
Process Argv C:\Users\s113093\Dropbox\portable-win\VSCode-win32-x64-1.26.0-insider\Code - Insiders.exe
Screen Reader no
VM 0%
Extensions (33)
Extension Author (truncated) Version
Bookmarks ale 9.0.3
project-manager ale 8.0.0
spellright ban 2.5.24
path-intellisense chr 1.4.2
vscode-svgviewer css 1.4.4
vscode-markdownlint Dav 0.19.0
githistory don 0.4.2
jupyter don 1.1.4
vscode-pandoc Dou 0.0.8
gitlens eam 8.5.4
vsc-material-theme Equ 2.3.0
prettier-vscode esb 1.5.0
vscode-diff fab 1.3.2
latex-workshop Jam 5.7.0
python ms- 2018.7.1
PowerShell ms- 1.8.2
wordcount ms- 0.1.0
vsliveshare ms- 0.3.504
gremlins nho 0.7.0
vscode-docker Pet 0.1.0
quicktype qui 12.0.15
vscode-icons rob 7.24.0
partial-diff ryu 1.3.0
markdown-preview-enhanced shd 0.3.5
vscode-spotify shy 2.5.1
vscode-fileutils sle 2.10.3
slack soz 0.0.14
code-spell-checker str 1.6.10
pdf tom 0.3.0
vscode-terminal-here Tyr 0.1.1
vscodeintellicode Vis 1.0.1
vscode-todo-highlight way 1.0.4
markdown-all-in-one yzh 1.6.0

(2 theme extensions excluded)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions