Commit 385e3a10 authored by Łukasz Langa's avatar Łukasz Langa
Browse files

Don't allow indexing to trigger omitting optional parentheses

parent 5dfc911e
Loading
Loading
Loading
Loading
+12 −2
Changes for black.py: 12 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -2064,12 +2064,22 @@ def right_hand_split(
    ):
        omit = {id(closing_bracket), *omit}
        delimiter_count = body.bracket_tracker.delimiter_count_with_priority()
        first = body.leaves[0]
        last = body.leaves[-1]
        if (
            delimiter_count == 0
            or delimiter_count == 1
            and (
                body.leaves[0].type in OPENING_BRACKETS
                or body.leaves[-1].type in CLOSING_BRACKETS
                first.type in OPENING_BRACKETS
                or last.type == token.RPAR
                or last.type == token.RBRACE
                or (
                    # don't use indexing for omitting optional parentheses;
                    # it looks weird
                    last.type == token.RSQB
                    and last.parent
                    and last.parent.type != syms.trailer
                )
            )
        ):
            try:
+3 −5
Changes for tests/composition.py: 3 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -32,11 +32,6 @@ def test(self) -> None:
                        # Another
                    ):
                        print(i)
            if _cfg_target_split > [int(x) for x in cur_target.split(".")]:
                my_msg = "$MACOSX_DEPLOYMENT_TARGET mismatch: " 'now "%s" but "%s" during configure' % (
                    cur_target,
                    _cfg_target,
                )

    def omitting_trailers(self) -> None:
        get_collection(
@@ -48,6 +43,9 @@ def omitting_trailers(self) -> None:
        d[0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][
            22
        ]
        assignment = (
            some.rather.elaborate.rule() and another.rule.ending_with.index[123]
        )

    def easy_asserts(self) -> None:
        assert {