Questions tagged [black-code-formatter]
16 questions
14
votes
2 answers
Problem with using Black code formatter; can't import _ast3
I want to use "Black code formatter" for one of my python projects. I've successfully installed it with "pip install black", which gave an output in the cmd which showed that all requirements were already satisfied (including…

Åsmund Sælen
- 171
- 1
- 2
- 6
9
votes
2 answers
Issue using Black formatter in PyCharm
I am trying to setup the formatter "black" to work with PyCharm. I have tried setting it up with both the standard External Tools preferences and using the Files Watcher Plugin. Neither has worked for me.
I am getting these errors:
I have it…

Scott K.
- 191
- 1
- 2
- 12
8
votes
1 answer
How do I configure black to use different formatting rules for different file extensions?
I use black for format normal .py files as well as Jupyter Notebook files (.ipynb). For notebooks, I want a shorter line-length.
Is it possible to specify different formatting rules for different file extensions with black?

william_grisaitis
- 5,170
- 3
- 33
- 40
5
votes
1 answer
Python Black Code Formatter - Is there any way to apply automatic black formatting before commiting project to Github
Recently I started to use Black code formatter for my projects and sometimes it can be hard to track did I formatted all my changed files or not.
Let's assume that my project contains 20 different scripts (.py files) and I made changes on last 5 of…
user10949197
5
votes
1 answer
How to make VSCode honor black excluded files in pyproject.toml configuration when using formatOnSave
I have the following pyproject.toml for configuring black:
[tool.black]
exclude = 'foo.py'
If I run black . from the project's root folder that only contains foo.py, I get No Python files are present to be formatted. Nothing to do � as…

frankundfrei
- 296
- 3
- 11
3
votes
1 answer
Getting Black Python code formatter to align comments
Yes, I'm, of the understanding that black gives very little leeway in getting it to act differently but I was wondering about the best way to handle something like this (my original code):
@dataclass
class Thing1:
property1: int …

paxdiablo
- 854,327
- 234
- 1,573
- 1,953
3
votes
1 answer
What is the best way to resolve git conflicts after reformatting entire python code base with black?
Suppose there is a large project not adhering to a specific python formatting standard, and you want to reformat all the python code using the python formatter black, and suppose the large scale project is pretty big (let's say ~2,000 python…

JavaNoob
- 31
- 1
3
votes
0 answers
How to force reformat file with black code formatter
I have a file in a git repo that is not reformatted for reason wasn't modified on disk since last run.
But eventually, a change is made in the file e.g new line. And a whole lot of major reformatting is done by black.
The file seems to have pending…

Arnold Taremwa
- 33
- 2
- 6
1
vote
2 answers
Is there a way to define keymap shortcuts for external tools depending on the file type, in PyCharm?
One use case would be to have the black code formatter for python files, and the sqlfluff code formatter for SQL files, and to use the same keyboard shortcut for both tools.
Currently, both are set up in Preferences -> Tools -> External Tools,…

alxthm
- 57
- 1
- 6
0
votes
0 answers
jupyterlab_code_formatter: multi-line list in code, specify items/characters per line?
jupyterlab_code_formatter installed for Jupyter lab
Black, isort, YAPF, Autopep8 added for jupyterlab_code_formatter
Question: which config should I twist if I want the auto-formatted list to not be one item per line.
# what it is doing now…

shaoooo
- 1
- 1
- 2
0
votes
1 answer
Black make function arguments formatting without new lines around barackets
I'd like to format function argumetns in a way similar to the PyCharm default formatting - see image. Meaning no new line after '(' and before ) so it does NOT look like in the second image. It looks cleaner to me when function name is more…

mCs
- 2,591
- 6
- 39
- 66
0
votes
0 answers
Applying Black formatter on symlink directory
I have the following folder structure:
- etl
- raw
- raw.py
- etl (symlink)
- raw
- raw.py
- etl (symlink)
... (infinite paths)
- config.py
I've created a symlink…

Matheus Schaly
- 163
- 4
- 21
0
votes
1 answer
Module not found when trying to run `black` in a Jupyter notebook
I've created a Jupyter notebook inside of a virtual environment.
These packages are installed:
black==22.12.0
jupyter~= 1.0.0
jupyter-black==0.3.3
jupyter-contrib-nbextensions~=0.5.1
In my notebook, there's a button with a little gavel to run black…

canary_in_the_data_mine
- 2,193
- 2
- 24
- 28
0
votes
0 answers
Formatter Black is not working on save (VSC)
{
"workbench.colorTheme": "Default Dark+",
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
"python.formatting.provider": "black",
"editor.formatOnSave": true,
"files.associations": {
"**/*.html": "html",
…
0
votes
1 answer
Vim format Python code with Black and then force tabs
I'm using the ALE plugin to format Python code with Black. Black indents the file with spaces (it's the same case with AutoPep8), but I want to keep my tabs. So I wrote this keybinding to run Black then swap spaces with tabs:
nnoremap ff…

Ameer Taweel
- 949
- 1
- 11
- 37