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
6
votes
1 answer

How to format this code so that flake8 is happy?

This code was created by black: def test_schema_org_script_from_list(): assert ( schema_org_script_from_list([1, 2]) == '\n' ) But now…
guettli
  • 25,042
  • 81
  • 346
  • 663
5
votes
2 answers

Is it possible to run isort formatter from black command in python

I like to get inspiration from well designed python projects. The last one that inspired me was the poetry repository. I copied a lot from that, but the subject of this post are black and isort. Both are well configured in…
emonier
  • 293
  • 1
  • 3
  • 13
5
votes
0 answers

How can I run black formatting on a cookiecutter template?

I am using pre-commit with black and flake8 hooks. I got this error: cannot format when trying to black-format the following code from {{cookiecutter.project_name}} import my_module Is there anyway to indicate black, to skip/ignore…
4
votes
1 answer

Black not respecting extend-exclude in pyproject.toml

In VSCode, with Python 3.9 and black==22.6.0, I have a project structure like: ---…
4
votes
1 answer

Format code in vscode setting for line break

We can use Ctrl+Shift+i for auto-formatting codes in vs code. vscode break lines longer that 80 character. Changing linewidth does not change it. I want to put that 120 in my python code. What is the solution? I did not find similar questions…
Abolfazl
  • 1,047
  • 2
  • 12
  • 29
4
votes
3 answers

How to change default line length for black or flake8 in a poetry virtual environment?

I have loaded black and flake8 into a poetry virtual environment. I'd like to change the default line length in black or flake8 so they agree. What is the best way to do this?
user12865812
  • 87
  • 1
  • 2
  • 6
3
votes
5 answers

Nesting long lists and sets using black formatter

Can the python black formatter nest long lists and sets? For example: Input coworkers = {"amy", "bill", "raj", "satoshi", "jim", "lifeng", "jeff", "sandeep", "mike"} Default output coworkers = { "amy", "bill", "raj", "satoshi", …
irahorecka
  • 1,447
  • 8
  • 25
3
votes
1 answer

Black ignores skip-string-normalization flag

In my pre-commit configuration I have black version 19.10b0 and in pyproject.toml I have line: skip-string-normalization = true So my strings don't get double quotes normalized. But then I run pre-commit autoupdate, black version upgrades to 20.8b1…
sgt pepper
  • 504
  • 7
  • 15
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…
3
votes
1 answer

PEP8 multi-line dict with multi-line value

I use Black for Python, which conforms to PEP8. It removes the indentation from the second line of a two line long value string: mydict = { 'key0': 'value0', 'key1': 'long-two-lines-string-value1-does-not-fit-in-one-line-has-to-continue' …
gsamaras
  • 71,951
  • 46
  • 188
  • 305
3
votes
1 answer

How do I get black code formatting in jupyter notebooks run from a docker container?

I'm able to get Jupyter working just fine from a docker container, and even get Jupyter extensions working from a docker container if they're part of jupyter_contrib_nbextensions, but I can't get the jupyter-black extension working from a docker…
Ben Lindsay
  • 1,686
  • 4
  • 23
  • 44
3
votes
1 answer

Long string remains unchanged, can python-black convert them into multine

Before: value = "aldkfdskdksfjdskfj dslkfj sdkl dklsfj dsklfj sdklfjdsklfjdskl fjdskl jdsklf jdsklfj dsklfj dsklfj dsklfj dsklfj dsklfj dsklfj dkl" After running black --line-length 80 file.py: (long string remains unchanged) value =…
alper
  • 2,919
  • 9
  • 53
  • 102
3
votes
1 answer

Is there a way to get git commit --verbose to show an updated diff when using pre-commit hooks?

So I'm currently setting up a git pre-commit hook to lint my python files with iSort, and python Black, the issue I'm running into is that when I use git commit --verbose the diff that shows up in the commit editor hasn't actually taken the…
DJ SymBiotiX
  • 187
  • 2
  • 12
2
votes
0 answers

How to make Black and Isort work with Auto Save on VSCode?

To make Black and Isort below work, I need to save manually by pressing Ctrl+S on VSCode: // "settings.json" { ... "[python]": { "editor.defaultFormatter": "ms-python.black-formatter", // For Black "editor.formatOnSave":…
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
2
votes
1 answer

How to run black/isort on check-only mode for vscode?

I could not find the way how to run black/isort on "read-only" mode, i.e., --check/--check-only flag on VSCode. There was "format on save" option, but I prefer "check where is wrong line and run formatter manually" way. (That is, I want to use…
keisuke
  • 2,123
  • 4
  • 20
  • 31