Unverified Commit e3ccabb2 authored by Bryan Bugyi's avatar Bryan Bugyi Committed by GitHub
Browse files

Fix unstable formatting on string split + % formatting (#1680)

Fixes #1595
parent 6b5753a4
Loading
Loading
Loading
Loading
+1 −1
Changes for src/black/__init__.py: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -2668,9 +2668,9 @@ def rhs(line: Line, features: Collection[Feature]) -> Iterator[Line]:
                transformers = [
                    string_merge,
                    string_paren_strip,
                    string_split,
                    delimiter_split,
                    standalone_comment_split,
                    string_split,
                    string_paren_wrap,
                    rhs,
                ]
+1 −2
Changes for src/blib2to3/pgen2/pgen.py: 1 added line, 2 removed lines.
Original line number Diff line number Diff line
@@ -168,8 +168,7 @@ def calcfirst(self, name: Text) -> None:
                if symbol in inverse:
                    raise ValueError(
                        "rule %s is ambiguous; %s is in the first sets of %s as well"
                        " as %s"
                        % (name, symbol, label, inverse[symbol])
                        " as %s" % (name, symbol, label, inverse[symbol])
                    )
                inverse[symbol] = label
        self.first[name] = totalset
+2 −4
Changes for tests/data/long_strings.py: 2 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -380,8 +380,7 @@ def foo():

old_fmt_string1 = (
    "While we are on the topic of %s, we should also note that old-style formatting"
    " must also be preserved, since some %s still uses it."
    % ("formatting", "code")
    " must also be preserved, since some %s still uses it." % ("formatting", "code")
)

old_fmt_string2 = "This is a %s %s %s %s" % (
@@ -448,8 +447,7 @@ def foo():

assert some_type_of_boolean_expression, (
    "Followed by a really really really long string that is used to provide context to"
    " the AssertionError exception, which uses dynamic string %s."
    % "formatting"
    " the AssertionError exception, which uses dynamic string %s." % "formatting"
)

assert some_type_of_boolean_expression, (
+17 −4
Changes for tests/data/long_strings__regression.py: 17 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -310,6 +310,13 @@ def who(self):
            passenger_association=passenger_association,
        )

if __name__ == "__main__":
    for i in range(4, 8):
        cmd = (
            r"for pid in $(ps aux | grep paster | grep -v grep | grep '\-%d' | awk '{print $2}'); do kill $pid; done"
            % (i)
        )

# output


@@ -435,14 +442,12 @@ def foo():

func_call_where_string_arg_has_old_fmt_and_bad_parens(
    "A long string with {}. This string is so long that it is ridiculous. It can't fit"
    " on one line at alllll."
    % "formatting",
    " on one line at alllll." % "formatting",
)

func_call_where_string_arg_has_old_fmt_and_bad_parens(
    "A long string with {}. This {} is so long that it is ridiculous. It can't fit on"
    " one line at alllll."
    % ("formatting", "string"),
    " one line at alllll." % ("formatting", "string"),
)


@@ -702,3 +707,11 @@ def who(self):
                passenger_association=passenger_association,
            )
        )


if __name__ == "__main__":
    for i in range(4, 8):
        cmd = (
            r"for pid in $(ps aux | grep paster | grep -v grep | grep '\-%d' | awk"
            r" '{print $2}'); do kill $pid; done" % (i)
        )