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

Fixes #1595
This commit is contained in:
Bryan Bugyi 2020-09-05 20:24:00 -04:00 committed by GitHub
parent 6b5753a417
commit e3ccabb23c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 11 deletions

View File

@ -2668,9 +2668,9 @@ def rhs(line: Line, features: Collection[Feature]) -> Iterator[Line]:
transformers = [ transformers = [
string_merge, string_merge,
string_paren_strip, string_paren_strip,
string_split,
delimiter_split, delimiter_split,
standalone_comment_split, standalone_comment_split,
string_split,
string_paren_wrap, string_paren_wrap,
rhs, rhs,
] ]

View File

@ -168,8 +168,7 @@ def calcfirst(self, name: Text) -> None:
if symbol in inverse: if symbol in inverse:
raise ValueError( raise ValueError(
"rule %s is ambiguous; %s is in the first sets of %s as well" "rule %s is ambiguous; %s is in the first sets of %s as well"
" as %s" " as %s" % (name, symbol, label, inverse[symbol])
% (name, symbol, label, inverse[symbol])
) )
inverse[symbol] = label inverse[symbol] = label
self.first[name] = totalset self.first[name] = totalset

View File

@ -380,8 +380,7 @@ def foo():
old_fmt_string1 = ( old_fmt_string1 = (
"While we are on the topic of %s, we should also note that old-style formatting" "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." " must also be preserved, since some %s still uses it." % ("formatting", "code")
% ("formatting", "code")
) )
old_fmt_string2 = "This is a %s %s %s %s" % ( old_fmt_string2 = "This is a %s %s %s %s" % (
@ -448,8 +447,7 @@ def foo():
assert some_type_of_boolean_expression, ( assert some_type_of_boolean_expression, (
"Followed by a really really really long string that is used to provide context to" "Followed by a really really really long string that is used to provide context to"
" the AssertionError exception, which uses dynamic string %s." " the AssertionError exception, which uses dynamic string %s." % "formatting"
% "formatting"
) )
assert some_type_of_boolean_expression, ( assert some_type_of_boolean_expression, (

View File

@ -310,6 +310,13 @@ def who(self):
passenger_association=passenger_association, 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 # output
@ -435,14 +442,12 @@ def foo():
func_call_where_string_arg_has_old_fmt_and_bad_parens( 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" "A long string with {}. This string is so long that it is ridiculous. It can't fit"
" on one line at alllll." " on one line at alllll." % "formatting",
% "formatting",
) )
func_call_where_string_arg_has_old_fmt_and_bad_parens( 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" "A long string with {}. This {} is so long that it is ridiculous. It can't fit on"
" one line at alllll." " one line at alllll." % ("formatting", "string"),
% ("formatting", "string"),
) )
@ -702,3 +707,11 @@ def who(self):
passenger_association=passenger_association, 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)
)