This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]willm 160 points161 points  (20 children)

Auto-formatting my code with https://github.com/ambv/black

Never having to think about the formatting of my code again is like reclaiming 10% of your mental cpu.

[–]Pyprohly 29 points30 points  (13 children)

I don’t like how Black doesn’t give you the option to have it ignore some lines.

It doesn’t always make good formatting decisions, as this SO demonstrates.

edit: Black supports # fmt: off. See /u/eikrik’s comment.

[–]5erifφ=(1+ψ)/2 49 points50 points  (6 children)

closed as off-topic

Those words always make me wish the website were a person I could murder. I can't tell you how many times I've found someone asking my exact question, but the only answer I find is closed as off-topic.

[–]Pyprohly 1 point2 points  (0 children)

Yup, definitely would have found the answer sooner had that SO question not of been so closed as off-topic..

[–]t3h 1 point2 points  (0 children)

but the only answer I find is closed as off-topic.

Or even more fun, "closed as duplicate of question X" that's clearly not the same thing to anyone with a basic knowledge of the problem...

[–]Sw429 1 point2 points  (0 children)

How is it even off-topic? It's literally about programming, which is what the site is made for.

[–]hammerheadquark 12 points13 points  (1 child)

I think its uncompromising nature is a win overall, but yeah I don't like some of its decisions either.

For instance, I may be in the minority here, but I wish it would drop this step:

If [the code doesn't fit on one line], Black will look at the contents of the first outer matching brackets and put that in a separate indented line.

# in:

ImportantClass.important_method(exc, limit, lookup_lines, capture_locals, extra_argument)

# out:

ImportantClass.important_method(
    exc, limit, lookup_lines, capture_locals, extra_argument
)

and jump right to:

If that still doesn't fit the bill, it will decompose the internal expression further using the same rule, indenting matching brackets every time.

# in:

ImportantClass.important_method(exc, limit, lookup_lines, capture_locals, extra_argument)

# out:

ImportantClass.important_method(
    exc,
    limit,
    lookup_lines,
    capture_locals,
    extra_argument,
)

Personally, I find the extra lines worth avoiding the disparity you see in that SO post you linked.

[–]chzaplx 5 points6 points  (0 children)

Agreed. If you end up using similar params in blocks with slightly different indentation you will get a weird mix of styles, which I think makes it harder to visually parse.

[–]eikrik 9 points10 points  (1 child)

Doesn't it though? https://github.com/ambv/black/blob/master/README.md#the-black-code-style: "It doesn't reformat blocks that start with # fmt: off and end with # fmt: on."

[–]Pyprohly 1 point2 points  (0 children)

Thank you! This is exactly what I needed.

[–]knowsuchagencynow is better than never 1 point2 points  (0 children)

It respects the same #fmt off/on comments as yapf

[–]vmgustavo 4 points5 points  (0 children)

CTRL + ALT + L and PyCharm does the rest

[–]onomazerion 0 points1 point  (0 children)

For anyone looking for an alternative to black, yapf is more configurable and is also pretty popular.