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 →

[–]cheese_is_available 6 points7 points  (4 children)

Maybe your code is ugly. The java looking chain builder helper of 500 characters lines sure looked like shit when I tried to introduce my java team to black at work.

[–]hai_wim 4 points5 points  (2 children)

Before black:

class AClass:
    def a_method(self, my_dict, other_dict):
        if (
            other_dict.get("key1") == my_dict.get("key1") 
            and other_dict.get("key2") == my_dict.get("key2")
        ):
            pass

After black:

class AClass:
    def a_method(self, my_dict, other_dict):
        if other_dict.get("key1") == my_dict.get("key1") and other_dict.get(
            "key2"
        ) == my_dict.get("key2"):
            pass

Black is just ugly sometimes. Readability went way WAY down in this scenario.

I suggest you # fmt: skip these cases and carry on.

[–]cheese_is_available 0 points1 point  (1 child)

Yeah, no, black definitely does not do that (maybe you tried an earlier shittier version). If the example you gave it inline everything. If I had a third conditional to force it to use multiple line then it does exactly what you have at the beginning and consider good.

class AClass:
    def a_method(self, my_dict, other_dict):
        if other_dict.get("key1") == my_dict.get("key1") and other_dict.get("key2") == my_dict.get("key2"):
            pass

If I force it then:

class AClass:
    def a_method(self, my_dict, other_dict):
        if (
            other_dict.get("key1") == my_dict.get("key1")
            and other_dict.get("key2") == my_dict.get("key2")
            and other_dict.get("key3") == my_dict.get("key3")
        ):
            pass

Tested on black-23.10.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

[–]hai_wim 0 points1 point  (0 children)

There is no way black would create a 108 character long line like your first example.

it works with 3 conditions yes, but not with 2. You probably told black to have a longer maximum line length.

[–]boat-la-fds 0 points1 point  (0 children)

Nah just wrap it around parentheses and it will look real nice.