Questions tagged [python-black]

Black is the uncompromising Python code formatter.

Black is the uncompromising Python code formatter.

Blackened code looks the same regardless of the project you're reading. Formatting becomes transparent after a while and you can focus on the content instead.

91 questions
2
votes
2 answers

How do you tell the version of the Python formatter being used by VS Code?

As stated on this answer, one can check (and set) on settings.json the formatters used by VS Code. For Python, I use black: settings.json ... "python.formatting.provider": "black" ... I think I found an issue involving black, but I'm only able to…
Sam
  • 1,222
  • 1
  • 14
  • 45
2
votes
1 answer

Black python formatter not working in zsh

I use the python formatter Black, but when I switched to zsh it stop working. Every time I try to use it manually through the terminal I get zsh: command not found: black I have it installed here /Users/HBrovell/Library/Python/3.7/bin/black and…
hbrovell
  • 547
  • 6
  • 17
2
votes
1 answer

FilePath macro does not contain value in Pycharm

I have installed the Python Black code formatter (https://github.com/psf/black). I want to integrate it into my PyCharm as an external tool. I have added the arguments of Black but the $FilePath$ macro does not provide the path of current file. My…
milanbalazs
  • 4,811
  • 4
  • 23
  • 45
1
vote
1 answer

Allow very long "from .." imports for black in order to stick to max line length?

In our projects instead of using relative imports, we usually create the code as python packages and install them with pip install -e . This is nice and prevents from issues with import errors on different machines/IDEs. However, for bigger project…
Roland Deschain
  • 2,211
  • 19
  • 50
1
vote
1 answer

What to do when your formatter and your linter are fighting

I've been writing a decorator in Python: def dictionary_updater(key: str) -> Callable[[FieldStringer], PayloadSetter]: """Convert string-converter to dictionary modifier. """ # Create the actual decorator method and return it def…
Woody1193
  • 7,252
  • 5
  • 40
  • 90
1
vote
1 answer

Different results running Black formatter standalone vs. from PyDev

When I run Black formatter (configured as a path to the executable) on file save in PyDev it inserts empty lines around functions, but when I run the same executable from command line it does not. Both invocations are using the same pyproject.toml…
VladG
  • 105
  • 7
1
vote
1 answer

Install black[d] from conda

I want to run black as a code formatter in PyCharm. The black website gives specific instructions on how to do so, which is very helpful: https://black.readthedocs.io/en/stable/integrations/editors.html . However, it uses pip to install black[d]…
Gianluca Micchi
  • 1,584
  • 15
  • 32
1
vote
1 answer

Automatically modernize python syntax

I'm looking for a tool that will automatically modernize my python code. Something that will take a python version as configuration, and automatically modernize the code for that version. For example, with python 3.9+ we can convert all from typing…
niltz
  • 1,014
  • 11
  • 28
1
vote
1 answer

How to run external command in neovim on BufWritePre set in Lua

I would like to format my code using /bin/black everytime I save a python file in neovim. So I have the following in my ~/.config/nvim/init.lua a.nvim_create_autocmd( { "BufWritePre" }, { pattern = { "*.py" }, command = [[ /bin/black ]], }) but…
DDStackoverflow
  • 505
  • 1
  • 11
  • 26
1
vote
1 answer

How do I force Jupyter Lab to revert a file

I have a Jupyter Notebook open in Jupyter Lab. I run black to reformat the code in the open Jupyter Notebook. If I try to save the file, Jupyter Lab raises "notebook.ipynb" has changed on disk since the last time it was opened or saved. Do you want…
Raniere Silva
  • 2,527
  • 1
  • 18
  • 34
1
vote
0 answers

PyCharm Black integration

I followed the instructions on this website to setup Black on my PyCharm (I followed the Windows steps). I have set it to run on every save and I already have a keybinding set for it as well. When I run this, it gives me the following error: error:…
arpanet101
  • 183
  • 1
  • 11
1
vote
1 answer

GitLab CI image: alpine "apk: command not found" error

I'm trying to follow this tutorial to enable formatting checks using black in GitLab CI. To make things simpler, I've transferred the code from .lint-ci.yml over to .gitlab-ci.yml. The tag of the shared runner that I'm using is gitlab-ci. I'm…
BubbleMaster
  • 184
  • 2
  • 10
1
vote
1 answer

How to get black - the python formatter - to work on vscode dev container?

I am currently developer in a dev container and I am trying to use black as a formatter for python. However, I failed to make it work. Here is my .devcontainer.json { "name": "api", "dockerComposeFile": ["../docker-compose.yml",…
Sami Al-Subhi
  • 4,406
  • 9
  • 39
  • 66
1
vote
1 answer

Python Black hooks (language: system)

I am using black on pre-commit and this is the hook - repo: https://github.com/psf/black rev: 19.10b0 hooks: - id: black this is the CI config I am using for black black --check . and it will reformat some files in the…
1
vote
1 answer

Why does NeoVim, Coc, Jedi, Mypy, ... generate some_name.py.[git hash].py files?

I have a rather basic NeoVim setup with Coc for working with Python files. My Coc config looks like this: { "python.setLinter": ["mypy"], "python.linting.enabled": false, "python.linting.mypyEnabled": true, "python.formatting.provider":…
Achim
  • 15,415
  • 15
  • 80
  • 144