Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Black (Python) Ignore Rule

I feel Black is doing something not compliant (with my Organisation), so I am trying to ignore certain rules.

Example below and a related link

PEP 8: whitespace before ':'

My Organisation (Coding Standards) does not give priority to what Black feels is right, but wants a way to customise black configurations.

I dont see any mentioned of Ignoring a Rule in Black documentation https://github.com/psf/black#command-line-options.

They have given examples to ignore Flake8 rules, but dont seem to have any documentation for their own product.

like image 564
Srinath Ganesh Avatar asked Feb 12 '20 13:02

Srinath Ganesh


2 Answers

You can't customize black. From the readme:

Black reformats entire files in place. It is not configurable.

like image 200
Patrick Avatar answered Oct 11 '22 13:10

Patrick


While you can't cherry-pick certain rules to disable, you can skip formatting for individual lines (using # fmt: skip at the end of the line), or for blocks of code (wrapping the code with # fmt: on and # fmt: off)

https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#code-style

And if using PyCharm, here's a guide for skipping certain lines without using the fmt comments: https://godatadriven.com/blog/partial-python-code-formatting-with-black-pycharm/

Edit: implement @kgadek correction

like image 10
djangomachine Avatar answered Oct 11 '22 13:10

djangomachine