I'm trying to have python files format on save using black and neovim, with coc.

Coc config

I have the following coc config:

  "coc.preferences.useQuickfixForLocations": true,
  "coc.preferences.snippets.enable": true,

  // python config
  "python.venvFolders": [".virtualenvs"],
  "python.venvPath" : "~/",
  "python.linting.enabled": true,
  "python.linting.pylintEnabled": true,
  "python.jediEnabled": false,
  "python.formatting.provider": "black",
  "python.formatting.blackPath": "~/.virtualenvs/neovim/bin/black",
  "coc.preferences.formatOnSaveFiletypes": ["python"]

Venv packages

Within the venv above I have the following black version:

-> % which python

(neovim) x@y [14:31:38] [~/.virtualenvs]
-> % pip list | grep black
black           19.10b0

Other packages in this env are:

-> % pip list
Package         Version
--------------- ---------
appdirs         1.4.4
attrs           19.3.0
black           19.10b0
click           7.1.2
greenlet        0.4.16
isort           5.1.4
jedi            0.17.2
msgpack         1.0.0
neovim          0.3.1
numpy           1.19.1
pandas          1.0.5
parso           0.7.1
pathspec        0.8.0
pip             20.1.1
pynvim          0.4.1
python-dateutil 2.8.1
pytz            2020.1
regex           2020.7.14
setuptools      41.2.0
six             1.15.0
toml            0.10.1
typed-ast       1.4.1

Behaviour / errors

I see no errors, but I see no results. For example I would expect the following to work given that setup is functioning:

# from
# to (having saved file)

I don't get this though, nothing happens.

Something unusual that does happen is that my buffer for a python file is constantly in need of saving. By which I mean - I constantly have No write since last change warning when trying to do :q, which makes me think there's something funny going on, but I don't know where.


Here is the output of :checkhealth

Edit 2

Black seems to be working, for me, these are settings that I currently have.


   "python.formatting.provider": "black",
   "python.formatting.blackPath": "~/.virtualenvs/neovim/bin/black",
   "coc.preferences.formatOnSaveFiletypes": ["python"]

I also have nothing of the psf/black plugin anymore, that was (i think) causing some issues.

  • 1
    For what it's worth, I use ALE w/ black enabled for python and fix-on-save, and I never have issues with black. – D. Ben Knoble Aug 1 '20 at 23:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.