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

How to satisfy output line length, code line length and Black code formatting at the same time? I.e. textwrap.wrap drop whitespace before wrapping?

This might be an XY-problem regarding the question about textwrap.wrap. I don't need to use textwrap.wrap if there's an easier way. I want to satisfy the following three criteria: Printed output text maximum line length of 70 Source code maximum…
finefoot
  • 9,914
  • 7
  • 59
  • 102
0
votes
2 answers

Only run black on changed files

I'm using the official black GitHub Action. Currently, whenever I push changes, black runs on the entire repository. However, I only want it to run on the changed files. I've tried using some of the GitHub environment variables, but to no avail.…
Klutch27
  • 167
  • 2
  • 9
0
votes
1 answer

is it possible to configure Black to error or warn on non-literal dict instantiation or similar?

When enforcing code style, my team prefers using a dict literal instead of the dict() function call: c = { "a": 1 } // good d = {} // good e = dict() // bad Can Black (or any linter or code formatter for python) do this?
BrDaHa
  • 5,138
  • 5
  • 32
  • 47
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
2 answers

black formatter: How can I place one newline before and after function instead of two

I am using black formatter. I have two newlines before and two newlines after function definition. I want one newline before and one newline after function definition. Can i do it using black config file black --config FILE. If so,how.
Ahmad Ismail
  • 11,636
  • 6
  • 52
  • 87
0
votes
1 answer

Python Black failed to format `print("\n", end='')`

The error: error: cannot format .py: Cannot parse: :: print("\n", end='') Why can't black format this code? If I remove it, Black just fails again at the next point that it encounters a print function with end…
Kalcifer
  • 1,211
  • 12
  • 18
0
votes
2 answers

Solve python ValueError: max_workers must be <= 61 when running pre-commit?

I am using Django to develop an ERP and I want to use pre-commit with my project. I have installed pre-commit, black, flake8, flake8-black. and this is my .pre-commit-config.yaml file configurations content repos: - repo:…
Dhia Shalabi
  • 1,332
  • 1
  • 13
  • 29
0
votes
1 answer

How to stop Black from removing new lines in function call args?

I want to document an external function: strange_function( # Comments about what this argument does param_1=True, # Comments about what this argument does param_2=False, ) Black reformats it as: strange_function( # Comments…
Rol
  • 501
  • 4
  • 13
0
votes
1 answer

Can you set Black so that it doesn't put ... statements on a newline?

I mostly agree with many of Black's formatting choices, including putting pass on a new line since usually it means I will implement the function later, but when I truly do want a function to be empty, I use ..., but then Black still puts it on a…
Th31AndOnly
  • 45
  • 1
  • 6
0
votes
1 answer

Running the Black formatter from Docker with a Makefile command

Rather than installing Black on my local machine, I'm experimenting with running Black (installed from requirements.txt) from a Docker container. I'm looking to add a Makefile command to format modified files. This is what I've come up with so far,…
strongdev
  • 3
  • 2
0
votes
2 answers

Getting "Extension 'Python Language Basics' cannot format ~'/'" even after configuring Black as formatter

I am trying to set up a formatter for VS Code. I would like to use Black, but I am struggling to get it to work. When I try to use the Format Document command, I get an error that says "Python auto formatting: Extension 'Python Language Basics'…
user12457151
  • 853
  • 2
  • 12
  • 25
0
votes
1 answer

mypy can't find type hints for black

I have a file test.py which only contains the line import black. When I run mypy test.py, I get the following error: test.py:1: error: Skipping analyzing 'black': found module but no type hints or library stubs test.py:1: note: See…
Nathan
  • 9,651
  • 4
  • 45
  • 65
0
votes
1 answer

Is it possible to have VS Code display formatter rules in the editor, like linters do?

With VS Code, when I use a linter like Flake8 or Pylint, it will underline sections of the code, and when I hover it will tell me the code of the rule being broken and a description. I would like to have the same functionality but for formatters…
draav
  • 1,454
  • 8
  • 8
0
votes
2 answers

With Python Black (prior to 19.2b), how to skip normalizing underscores in numeric literals?

I am using Black with Python 3.7 (in VS Code). When I format my code, the numeric literals are normalized with the underscore (e.g. 1562202 => 1_562_202). How to use Black Formatting without formatting by using the underscore? NOTE From black…
Jean-Francois T.
  • 11,549
  • 7
  • 68
  • 107
-2
votes
0 answers

Pre-commit error while finding branch name

I am new to pre-commit and I am trying to implement Black with pre-commit. The link to the documentation that I am following is given…