Improve String Handling (#1132)

This pull request's main intention is to wraps long strings (as requested by #182); however, it also provides better string handling in general and, in doing so, closes the following issues:

Closes #26
Closes #182
Closes #933
Closes #1183
Closes #1243
This commit is contained in:
Bryan Bugyi 2020-05-08 08:56:21 -04:00 committed by GitHub
parent 07c046b7cd
commit 544ea9c217
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 3578 additions and 186 deletions

2164
black.py

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -78,7 +78,9 @@ def _combinations(*l):
Whitespace = r"[ \f\t]*"
Comment = r"#[^\r\n]*"
Ignore = Whitespace + any(r"\\\r?\n" + Whitespace) + maybe(Comment)
Name = r"\w+" # this is invalid but it's fine because Name comes after Number in all groups
Name = ( # this is invalid but it's fine because Name comes after Number in all groups
r"\w+"
)
Binnumber = r"0[bB]_?[01]+(?:_[01]+)*"
Hexnumber = r"0[xX]_?[\da-fA-F]+(?:_[\da-fA-F]+)*[lL]?"

View File

@ -268,8 +268,7 @@ def main() -> None:
"-v",
"--version",
help=(
"Version for given PyPI package. "
"Will be discarded if used with -t option."
"Version for given PyPI package. Will be discarded if used with -t option."
),
)
parser.add_argument(

View File

@ -35,7 +35,7 @@
""".split():
if key in self.connect_kwargs:
raise ValueError(err.format(key))
concatenated_strings = "some strings that are" "concatenated implicitly, so if you put them on separate" "lines it will fit"
concatenated_strings = "some strings that are " "concatenated implicitly, so if you put them on separate " "lines it will fit"
del concatenated_strings, string_variable_name, normal_function_name, normal_name, need_more_to_make_the_line_long_enough
@ -75,8 +75,10 @@
)
# long arguments
normal_name = normal_function_name(
"but with super long string arguments that on their own exceed the line limit so there's no way it can ever fit",
"eggs with spam and eggs and spam with eggs with spam and eggs and spam with eggs with spam and eggs and spam with eggs",
"but with super long string arguments that on their own exceed the line limit so"
" there's no way it can ever fit",
"eggs with spam and eggs and spam with eggs with spam and eggs and spam with eggs"
" with spam and eggs and spam with eggs",
this_is_a_ridiculously_long_name_and_nobody_in_their_right_mind_would_use_one_like_it=0,
)
string_variable_name = "a string that is waaaaaaaayyyyyyyy too long, even in parens, there's nothing you can do" # noqa
@ -88,8 +90,8 @@
if key in self.connect_kwargs:
raise ValueError(err.format(key))
concatenated_strings = (
"some strings that are"
"concatenated implicitly, so if you put them on separate"
"some strings that are "
"concatenated implicitly, so if you put them on separate "
"lines it will fit"
)
del (

View File

@ -13,49 +13,39 @@ class C:
# metadata_version errors.
(
{},
"None is an invalid value for Metadata-Version. "
"Error: This field is required. "
"see "
"https://packaging.python.org/specifications/core-metadata",
"None is an invalid value for Metadata-Version. Error: This field is"
" required. see"
" https://packaging.python.org/specifications/core-metadata",
),
(
{"metadata_version": "-1"},
"'-1' is an invalid value for Metadata-Version. "
"Error: Unknown Metadata Version "
"see "
"https://packaging.python.org/specifications/core-metadata",
"'-1' is an invalid value for Metadata-Version. Error: Unknown Metadata"
" Version see"
" https://packaging.python.org/specifications/core-metadata",
),
# name errors.
(
{"metadata_version": "1.2"},
"'' is an invalid value for Name. "
"Error: This field is required. "
"see "
"https://packaging.python.org/specifications/core-metadata",
"'' is an invalid value for Name. Error: This field is required. see"
" https://packaging.python.org/specifications/core-metadata",
),
(
{"metadata_version": "1.2", "name": "foo-"},
"'foo-' is an invalid value for Name. "
"Error: Must start and end with a letter or numeral and "
"contain only ascii numeric and '.', '_' and '-'. "
"see "
"https://packaging.python.org/specifications/core-metadata",
"'foo-' is an invalid value for Name. Error: Must start and end with a"
" letter or numeral and contain only ascii numeric and '.', '_' and"
" '-'. see https://packaging.python.org/specifications/core-metadata",
),
# version errors.
(
{"metadata_version": "1.2", "name": "example"},
"'' is an invalid value for Version. "
"Error: This field is required. "
"see "
"https://packaging.python.org/specifications/core-metadata",
"'' is an invalid value for Version. Error: This field is required. see"
" https://packaging.python.org/specifications/core-metadata",
),
(
{"metadata_version": "1.2", "name": "example", "version": "dog"},
"'dog' is an invalid value for Version. "
"Error: Must start and end with a letter or numeral and "
"contain only ascii numeric and '.', '_' and '-'. "
"see "
"https://packaging.python.org/specifications/core-metadata",
"'dog' is an invalid value for Version. Error: Must start and end with"
" a letter or numeral and contain only ascii numeric and '.', '_' and"
" '-'. see https://packaging.python.org/specifications/core-metadata",
),
],
)

View File

@ -104,7 +104,9 @@ def func(
)
result = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # aaa
result = ( # aaa
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
)
AAAAAAAAAAAAA = [AAAAAAAAAAAAA] + SHARED_AAAAAAAAAAAAA + USER_AAAAAAAAAAAAA + AAAAAAAAAAAAA # type: ignore

View File

@ -87,9 +87,13 @@ def func():
result = 1 # look ma, no comment migration xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
result = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # aaa
result = ( # aaa
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
)
result = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # aaa
result = ( # aaa
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
)
def func():

View File

@ -10,13 +10,13 @@ def test(self) -> None:
)
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 1 file left unchanged, "
"1 file failed to reformat.",
"2 files reformatted, 1 file left unchanged, 1 file failed to"
" reformat.",
)
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 2 files left unchanged, "
"2 files failed to reformat.",
"2 files reformatted, 2 files left unchanged, 2 files failed to"
" reformat.",
)
for i in (a,):
if (
@ -40,8 +40,7 @@ def test(self) -> None:
items=items[:num_items]
)
return (
"Utterly failed doctest test for %s\n"
' File "%s", line %s, in %s\n\n%s'
'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
% (test.name, test.filename, lineno, lname, err)
)
@ -150,8 +149,8 @@ def tricky_asserts(self) -> None:
key8: value8,
key9: value9,
}, (
"Not what we expected and the message is too long to fit "
"in one line because it's too long"
"Not what we expected and the message is too long to fit in one line"
" because it's too long"
)
dis_c_instance_method = """\

563
tests/data/long_strings.py Normal file
View File

@ -0,0 +1,563 @@
x = "This is a really long string that can't possibly be expected to fit all together on one line. In fact it may even take up three or more lines... like four or five... but probably just three."
x += "This is a really long string that can't possibly be expected to fit all together on one line. In fact it may even take up three or more lines... like four or five... but probably just three."
y = (
'Short string'
)
print('This is a really long string inside of a print statement with extra arguments attached at the end of it.', x, y, z)
print("This is a really long string inside of a print statement with no extra arguments attached at the end of it.")
D1 = {"The First": "This is a really long string that can't possibly be expected to fit all together on one line. Also it is inside a dictionary, so formatting is more difficult.", "The Second": "This is another really really (not really) long string that also can't be expected to fit on one line and is, like the other string, inside a dictionary."}
D2 = {1.0: "This is a really long string that can't possibly be expected to fit all together on one line. Also it is inside a dictionary, so formatting is more difficult.", 2.0: "This is another really really (not really) long string that also can't be expected to fit on one line and is, like the other string, inside a dictionary."}
D3 = {x: "This is a really long string that can't possibly be expected to fit all together on one line. Also it is inside a dictionary, so formatting is more difficult.", y: "This is another really really (not really) long string that also can't be expected to fit on one line and is, like the other string, inside a dictionary."}
D4 = {"A long and ridiculous {}".format(string_key): "This is a really really really long string that has to go i,side of a dictionary. It is soooo bad.", some_func("calling", "some", "stuff"): "This is a really really really long string that has to go inside of a dictionary. It is {soooo} bad (#{x}).".format(sooo="soooo", x=2), "A %s %s" % ("formatted", "string"): "This is a really really really long string that has to go inside of a dictionary. It is %s bad (#%d)." % ("soooo", 2)}
func_with_keywords(my_arg, my_kwarg="Long keyword strings also need to be wrapped, but they will probably need to be handled a little bit differently.")
bad_split1 = (
'But what should happen when code has already been formatted but in the wrong way? Like'
" with a space at the end instead of the beginning. Or what about when it is split too soon?"
)
bad_split2 = "But what should happen when code has already " \
"been formatted but in the wrong way? Like " \
"with a space at the end instead of the " \
"beginning. Or what about when it is split too " \
"soon? In the case of a split that is too " \
"short, black will try to honer the custom " \
"split."
bad_split3 = (
"What if we have inline comments on " # First Comment
"each line of a bad split? In that " # Second Comment
"case, we should just leave it alone." # Third Comment
)
bad_split_func1(
"But what should happen when code has already "
"been formatted but in the wrong way? Like "
"with a space at the end instead of the "
"beginning. Or what about when it is split too "
"soon? In the case of a split that is too "
"short, black will try to honer the custom "
"split.",
xxx, yyy, zzz
)
bad_split_func2(
xxx, yyy, zzz,
long_string_kwarg="But what should happen when code has already been formatted but in the wrong way? Like "
"with a space at the end instead of the beginning. Or what about when it is split too "
"soon?",
)
bad_split_func3(
(
"But what should happen when code has already "
r"been formatted but in the wrong way? Like "
"with a space at the end instead of the "
r"beginning. Or what about when it is split too "
r"soon? In the case of a split that is too "
"short, black will try to honer the custom "
"split."
),
xxx,
yyy,
zzz,
)
raw_string = r"This is a long raw string. When re-formatting this string, black needs to make sure it prepends the 'r' onto the new string."
fmt_string1 = "We also need to be sure to preserve any and all {} which may or may not be attached to the string in question.".format("method calls")
fmt_string2 = "But what about when the string is {} but {}".format("short", "the method call is really really really really really really really really long?")
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")
old_fmt_string2 = "This is a %s %s %s %s" % ("really really really really really", "old", "way to format strings!", "Use f-strings instead!")
old_fmt_string3 = "Whereas only the strings after the percent sign were long in the last example, this example uses a long initial string as well. This is another %s %s %s %s" % ("really really really really really", "old", "way to format strings!", "Use f-strings instead!")
fstring = f"f-strings definitely make things more {difficult} than they need to be for {{black}}. But boy they sure are handy. The problem is that some lines will need to have the 'f' whereas others do not. This {line}, for example, needs one."
fstring_with_no_fexprs = f"Some regular string that needs to get split certainly but is NOT an fstring by any means whatsoever."
comment_string = "Long lines with inline comments should have their comments appended to the reformatted string's enclosing right parentheses." # This comment gets thrown to the top.
arg_comment_string = print("Long lines with inline comments which are apart of (and not the only member of) an argument list should have their comments appended to the reformatted string's enclosing left parentheses.", # This comment stays on the bottom.
"Arg #2", "Arg #3", "Arg #4", "Arg #5")
pragma_comment_string1 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa: E501
pragma_comment_string2 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa
"""This is a really really really long triple quote string and it should not be touched."""
triple_quote_string = """This is a really really really long triple quote string assignment and it should not be touched."""
assert some_type_of_boolean_expression, "Followed by a really really really long string that is used to provide context to the AssertionError exception."
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 {}.".format("formatting")
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"
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 %s %s." % ("string", "formatting")
some_function_call("With a reallly generic name and with a really really long string that is, at some point down the line, " + added + " to a variable and then added to another string.")
some_function_call("With a reallly generic name and with a really really long string that is, at some point down the line, " + added + " to a variable and then added to another string. But then what happens when the final string is also supppppperrrrr long?! Well then that second (realllllllly long) string should be split too.", "and a second argument", and_a_third)
return "A really really really really really really really really really really really really really long {} {}".format("return", "value")
func_with_bad_comma(
"This is a really long string argument to a function that has a trailing comma which should NOT be there.",
)
func_with_bad_comma(
"This is a really long string argument to a function that has a trailing comma which should NOT be there.", # comment after comma
)
func_with_bad_comma(
(
"This is a really long string argument to a function that has a trailing comma"
" which should NOT be there."
),
)
func_with_bad_comma(
(
"This is a really long string argument to a function that has a trailing comma"
" which should NOT be there."
), # comment after comma
)
func_with_bad_parens(
("short string that should have parens stripped"),
x,
y,
z,
)
func_with_bad_parens(
x,
y,
("short string that should have parens stripped"),
z,
)
annotated_variable: Final = "This is a large " + STRING + " that has been " + CONCATENATED + "using the '+' operator."
annotated_variable: Final = "This is a large string that has a type annotation attached to it. A type annotation should NOT stop a long string from being wrapped."
annotated_variable: Literal["fakse_literal"] = "This is a large string that has a type annotation attached to it. A type annotation should NOT stop a long string from being wrapped."
backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\"
backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\\\"
backslashes = "This is a really 'long' string with \"embedded double quotes\" and 'single' quotes that also handles checking for an odd number of backslashes \\\", like this...\\\\\\"
short_string = (
"Hi"
" there."
)
func_call(
short_string=(
"Hi"
" there."
)
)
raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
def foo():
yield "This is a really long string that can't possibly be expected to fit all together on one line. In fact it may even take up three or more lines... like four or five... but probably just three."
x = f"This is a {{really}} long string that needs to be split without a doubt (i.e. most definitely). In short, this {string} that can't possibly be {{expected}} to fit all together on one line. In {fact} it may even take up three or more lines... like four or five... but probably just four."
long_unmergable_string_with_pragma = (
"This is a really long string that can't be merged because it has a likely pragma at the end" # type: ignore
" of it."
)
long_unmergable_string_with_pragma = (
"This is a really long string that can't be merged because it has a likely pragma at the end" # noqa
" of it."
)
long_unmergable_string_with_pragma = (
"This is a really long string that can't be merged because it has a likely pragma at the end" # pylint: disable=some-pylint-check
" of it."
)
# output
x = (
"This is a really long string that can't possibly be expected to fit all together"
" on one line. In fact it may even take up three or more lines... like four or"
" five... but probably just three."
)
x += (
"This is a really long string that can't possibly be expected to fit all together"
" on one line. In fact it may even take up three or more lines... like four or"
" five... but probably just three."
)
y = "Short string"
print(
"This is a really long string inside of a print statement with extra arguments"
" attached at the end of it.",
x,
y,
z,
)
print(
"This is a really long string inside of a print statement with no extra arguments"
" attached at the end of it."
)
D1 = {
"The First": (
"This is a really long string that can't possibly be expected to fit all"
" together on one line. Also it is inside a dictionary, so formatting is more"
" difficult."
),
"The Second": (
"This is another really really (not really) long string that also can't be"
" expected to fit on one line and is, like the other string, inside a"
" dictionary."
),
}
D2 = {
1.0: (
"This is a really long string that can't possibly be expected to fit all"
" together on one line. Also it is inside a dictionary, so formatting is more"
" difficult."
),
2.0: (
"This is another really really (not really) long string that also can't be"
" expected to fit on one line and is, like the other string, inside a"
" dictionary."
),
}
D3 = {
x: (
"This is a really long string that can't possibly be expected to fit all"
" together on one line. Also it is inside a dictionary, so formatting is more"
" difficult."
),
y: (
"This is another really really (not really) long string that also can't be"
" expected to fit on one line and is, like the other string, inside a"
" dictionary."
),
}
D4 = {
"A long and ridiculous {}".format(string_key): (
"This is a really really really long string that has to go i,side of a"
" dictionary. It is soooo bad."
),
some_func("calling", "some", "stuff"): (
"This is a really really really long string that has to go inside of a"
" dictionary. It is {soooo} bad (#{x}).".format(sooo="soooo", x=2)
),
"A %s %s"
% ("formatted", "string"): (
"This is a really really really long string that has to go inside of a"
" dictionary. It is %s bad (#%d)."
)
% ("soooo", 2),
}
func_with_keywords(
my_arg,
my_kwarg=(
"Long keyword strings also need to be wrapped, but they will probably need to"
" be handled a little bit differently."
),
)
bad_split1 = (
"But what should happen when code has already been formatted but in the wrong way?"
" Like with a space at the end instead of the beginning. Or what about when it is"
" split too soon?"
)
bad_split2 = (
"But what should happen when code has already "
"been formatted but in the wrong way? Like "
"with a space at the end instead of the "
"beginning. Or what about when it is split too "
"soon? In the case of a split that is too "
"short, black will try to honer the custom "
"split."
)
bad_split3 = (
"What if we have inline comments on " # First Comment
"each line of a bad split? In that " # Second Comment
"case, we should just leave it alone." # Third Comment
)
bad_split_func1(
"But what should happen when code has already "
"been formatted but in the wrong way? Like "
"with a space at the end instead of the "
"beginning. Or what about when it is split too "
"soon? In the case of a split that is too "
"short, black will try to honer the custom "
"split.",
xxx,
yyy,
zzz,
)
bad_split_func2(
xxx,
yyy,
zzz,
long_string_kwarg=(
"But what should happen when code has already been formatted but in the wrong"
" way? Like with a space at the end instead of the beginning. Or what about"
" when it is split too soon?"
),
)
bad_split_func3(
(
"But what should happen when code has already "
r"been formatted but in the wrong way? Like "
"with a space at the end instead of the "
r"beginning. Or what about when it is split too "
r"soon? In the case of a split that is too "
"short, black will try to honer the custom "
"split."
),
xxx,
yyy,
zzz,
)
raw_string = (
r"This is a long raw string. When re-formatting this string, black needs to make"
r" sure it prepends the 'r' onto the new string."
)
fmt_string1 = (
"We also need to be sure to preserve any and all {} which may or may not be"
" attached to the string in question.".format("method calls")
)
fmt_string2 = "But what about when the string is {} but {}".format(
"short",
"the method call is really really really really really really really really long?",
)
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")
)
old_fmt_string2 = "This is a %s %s %s %s" % (
"really really really really really",
"old",
"way to format strings!",
"Use f-strings instead!",
)
old_fmt_string3 = (
"Whereas only the strings after the percent sign were long in the last example,"
" this example uses a long initial string as well. This is another %s %s %s %s"
% (
"really really really really really",
"old",
"way to format strings!",
"Use f-strings instead!",
)
)
fstring = (
f"f-strings definitely make things more {difficult} than they need to be for"
" {black}. But boy they sure are handy. The problem is that some lines will need"
f" to have the 'f' whereas others do not. This {line}, for example, needs one."
)
fstring_with_no_fexprs = (
f"Some regular string that needs to get split certainly but is NOT an fstring by"
f" any means whatsoever."
)
comment_string = ( # This comment gets thrown to the top.
"Long lines with inline comments should have their comments appended to the"
" reformatted string's enclosing right parentheses."
)
arg_comment_string = print(
"Long lines with inline comments which are apart of (and not the only member of) an"
" argument list should have their comments appended to the reformatted string's"
" enclosing left parentheses.", # This comment stays on the bottom.
"Arg #2",
"Arg #3",
"Arg #4",
"Arg #5",
)
pragma_comment_string1 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa: E501
pragma_comment_string2 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa
"""This is a really really really long triple quote string and it should not be touched."""
triple_quote_string = """This is a really really really long triple quote string assignment and it should not be touched."""
assert some_type_of_boolean_expression, (
"Followed by a really really really long string that is used to provide context to"
" the AssertionError exception."
)
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 {}.".format("formatting")
)
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"
)
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 %s %s."
% ("string", "formatting")
)
some_function_call(
"With a reallly generic name and with a really really long string that is, at some"
" point down the line, "
+ added
+ " to a variable and then added to another string."
)
some_function_call(
"With a reallly generic name and with a really really long string that is, at some"
" point down the line, "
+ added
+ " to a variable and then added to another string. But then what happens when the"
" final string is also supppppperrrrr long?! Well then that second (realllllllly"
" long) string should be split too.",
"and a second argument",
and_a_third,
)
return (
"A really really really really really really really really really really really"
" really really long {} {}".format("return", "value")
)
func_with_bad_comma(
"This is a really long string argument to a function that has a trailing comma"
" which should NOT be there.",
)
func_with_bad_comma(
"This is a really long string argument to a function that has a trailing comma"
" which should NOT be there.", # comment after comma
)
func_with_bad_comma(
"This is a really long string argument to a function that has a trailing comma"
" which should NOT be there.",
)
func_with_bad_comma(
"This is a really long string argument to a function that has a trailing comma"
" which should NOT be there.", # comment after comma
)
func_with_bad_parens(
"short string that should have parens stripped", x, y, z,
)
func_with_bad_parens(
x, y, "short string that should have parens stripped", z,
)
annotated_variable: Final = (
"This is a large "
+ STRING
+ " that has been "
+ CONCATENATED
+ "using the '+' operator."
)
annotated_variable: Final = (
"This is a large string that has a type annotation attached to it. A type"
" annotation should NOT stop a long string from being wrapped."
)
annotated_variable: Literal["fakse_literal"] = (
"This is a large string that has a type annotation attached to it. A type"
" annotation should NOT stop a long string from being wrapped."
)
backslashes = (
"This is a really long string with \"embedded\" double quotes and 'single' quotes"
" that also handles checking for an even number of backslashes \\"
)
backslashes = (
"This is a really long string with \"embedded\" double quotes and 'single' quotes"
" that also handles checking for an even number of backslashes \\\\"
)
backslashes = (
"This is a really 'long' string with \"embedded double quotes\" and 'single' quotes"
' that also handles checking for an odd number of backslashes \\", like'
" this...\\\\\\"
)
short_string = "Hi there."
func_call(short_string="Hi there.")
raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
def foo():
yield (
"This is a really long string that can't possibly be expected to fit all"
" together on one line. In fact it may even take up three or more lines... like"
" four or five... but probably just three."
)
x = (
"This is a {really} long string that needs to be split without a doubt (i.e."
f" most definitely). In short, this {string} that can't possibly be {{expected}} to"
f" fit all together on one line. In {fact} it may even take up three or more"
" lines... like four or five... but probably just four."
)
long_unmergable_string_with_pragma = (
"This is a really long string that can't be merged because it has a likely pragma at the end" # type: ignore
" of it."
)
long_unmergable_string_with_pragma = (
"This is a really long string that can't be merged because it has a likely pragma at the end" # noqa
" of it."
)
long_unmergable_string_with_pragma = (
"This is a really long string that can't be merged because it has a likely pragma at the end" # pylint: disable=some-pylint-check
" of it."
)

View File

@ -0,0 +1,110 @@
some_variable = "This string is long but not so long that it needs to be split just yet"
some_variable = 'This string is long but not so long that it needs to be split just yet'
some_variable = "This string is long, just long enough that it needs to be split, u get?"
some_variable = 'This string is long, just long enough that it needs to be split, u get?'
some_variable = "This string is long, just long enough that it needs to be split, u get? So we stay"
some_variable = 'This string is long, just long enough that it needs to be split, u get? So we stay'
some_variable = "This string is long, just long enough that it needs to be split, u get? So we split"
some_variable = 'This string is long, just long enough that it needs to be split, u get? So we split'
some_variable = "This string is long but not so long that it needs hahahah toooooo be so greatttt {} that I just can't think of any more good words to say about it at alll".format("ha")
some_variable = "This string is long but not so long that it needs hahahah toooooo be so greatttt {} that I just can't think of any more good words to say about it at allll".format("ha")
some_variable = "This string is long but not so long that it needs hahahah toooooo be so greatttt {} that I just can't think of any more good words to say about it at alllllllllll".format("ha")
some_variable = "This string is long but not so long that it needs hahahah toooooo be so greatttt {} that I just can't think of any more good words to say about it at allllllllllll".format("ha")
some_variable = "This is a long string that will end with a method that is not calleddd".format
addition_inside_tuple = (
some_string_inside_a_variable
+ "Some string that is just long enough to cause a split to take place.............",
xyz,
"Some really long string that needs to get split eventually but I'm running out of things to say" + some_string_inside_a_variable
)
addition_inside_tuple = (
some_string_inside_a_variable
+ "Some string that is just long enough to cause a split to take place.............."
)
return "Hi there. This is areally really reallllly long string that needs to be split!!!"
ternary_expression = (
"Short String"
if some_condition
else "This is a really long string that will eventually need to be split right here."
)
return f'{x}/b/c/d/d/d/dadfjsadjsaidoaisjdsfjaofjdfijaidfjaodfjaoifjodjafojdoajaaaaaaaaaaa'
return f'{x}/b/c/d/d/d/dadfjsadjsaidoaisjdsfjaofjdfijaidfjaodfjaoifjodjafojdoajaaaaaaaaaaaa'
# output
some_variable = "This string is long but not so long that it needs to be split just yet"
some_variable = "This string is long but not so long that it needs to be split just yet"
some_variable = (
"This string is long, just long enough that it needs to be split, u get?"
)
some_variable = (
"This string is long, just long enough that it needs to be split, u get?"
)
some_variable = (
"This string is long, just long enough that it needs to be split, u get? So we stay"
)
some_variable = (
"This string is long, just long enough that it needs to be split, u get? So we stay"
)
some_variable = (
"This string is long, just long enough that it needs to be split, u get? So we"
" split"
)
some_variable = (
"This string is long, just long enough that it needs to be split, u get? So we"
" split"
)
some_variable = (
"This string is long but not so long that it needs hahahah toooooo be so greatttt"
" {} that I just can't think of any more good words to say about it at alll".format(
"ha"
)
)
some_variable = (
"This string is long but not so long that it needs hahahah toooooo be so greatttt"
" {} that I just can't think of any more good words to say about it at allll"
.format("ha")
)
some_variable = (
"This string is long but not so long that it needs hahahah toooooo be so greatttt"
" {} that I just can't think of any more good words to say about it at alllllllllll"
.format("ha")
)
some_variable = (
"This string is long but not so long that it needs hahahah toooooo be so greatttt"
" {} that I just can't think of any more good words to say about it at"
" allllllllllll".format("ha")
)
some_variable = (
"This is a long string that will end with a method that is not calleddd".format
)
addition_inside_tuple = (
some_string_inside_a_variable
+ "Some string that is just long enough to cause a split to take"
" place.............",
xyz,
"Some really long string that needs to get split eventually but I'm running out of"
" things to say"
+ some_string_inside_a_variable,
)
addition_inside_tuple = (
some_string_inside_a_variable
+ "Some string that is just long enough to cause a split to take"
" place.............."
)
return (
"Hi there. This is areally really reallllly long string that needs to be split!!!"
)
ternary_expression = (
"Short String"
if some_condition
else (
"This is a really long string that will eventually need to be split right here."
)
)
return (
f"{x}/b/c/d/d/d/dadfjsadjsaidoaisjdsfjaofjdfijaidfjaodfjaoifjodjafojdoajaaaaaaaaaaa"
)
return f"{x}/b/c/d/d/d/dadfjsadjsaidoaisjdsfjaofjdfijaidfjaodfjaoifjodjafojdoajaaaaaaaaaaaa"

View File

@ -0,0 +1,698 @@
class A:
def foo():
result = type(message)("")
# Don't merge multiline (e.g. triple-quoted) strings.
def foo():
query = (
"""SELECT xxxxxxxxxxxxxxxxxxxx(xxx)"""
""" FROM xxxxxxxxxxxxxxxx WHERE xxxxxxxxxx AND xxx <> xxxxxxxxxxxxxx()""")
# There was a bug where tuples were being identified as long strings.
long_tuple = ('Apple', 'Berry', 'Cherry', 'Dill', 'Evergreen', 'Fig',
'Grape', 'Harry', 'Iglu', 'Jaguar')
stupid_format_method_bug = "Some really long string that just so happens to be the {} {} to force the 'format' method to hang over the line length boundary. This is pretty annoying.".format("perfect", "length")
class A:
def foo():
os.system("This is a regression test. xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxxx.".format("xxxxxxxxxx", "xxxxxx", "xxxxxxxxxx"))
class A:
def foo():
XXXXXXXXXXXX.append(
(
"xxx_xxxxxxxxxx(xxxxx={}, xxxx={}, xxxxx, xxxx_xxxx_xxxxxxxxxx={})".format(
xxxxx, xxxx, xxxx_xxxx_xxxxxxxxxx
),
my_var,
my_other_var,
)
)
class A:
class B:
def foo():
bar(
(
"[{}]: xxx_xxxxxxxxxx(xxxxx={}, xxxx={}, xxxxx={}"
" xxxx_xxxx_xxxxxxxxxx={}, xxxx={})"
.format(xxxx._xxxxxxxxxxxxxx, xxxxx, xxxx, xxxx_xxxx_xxxxxxxxxx, xxxxxxx)
),
varX,
varY,
varZ,
)
def foo(xxxx):
for (xxx_xxxx, _xxx_xxx, _xxx_xxxxx, xxx_xxxx) in xxxx:
for xxx in xxx_xxxx:
assert ("x" in xxx) or (
xxx in xxx_xxx_xxxxx
), "{0} xxxxxxx xx {1}, xxx {1} xx xxx xx xxxx xx xxx xxxx: xxx xxxx {2}".format(
xxx_xxxx, xxx, xxxxxx.xxxxxxx(xxx_xxx_xxxxx)
)
class A:
def disappearing_comment():
return (
( # xx -x xxxxxxx xx xxx xxxxxxx.
'{{xxx_xxxxxxxxxx_xxxxxxxx}} xxx xxxx'
' {} {{xxxx}} >&2'
.format(
"{xxxx} {xxxxxx}"
if xxxxx.xx_xxxxxxxxxx
else ( # Disappearing Comment
"--xxxxxxx --xxxxxx=x --xxxxxx-xxxxx=xxxxxx"
" --xxxxxx-xxxx=xxxxxxxxxxx.xxx"
)
)
),
(x, y, z),
)
class A:
class B:
def foo():
xxxxx_xxxx(
xx, "\t"
"@xxxxxx '{xxxx_xxx}\t' > {xxxxxx_xxxx}.xxxxxxx;"
"{xxxx_xxx} >> {xxxxxx_xxxx}.xxxxxxx 2>&1; xx=$$?;"
"xxxx $$xx"
.format(xxxx_xxx=xxxx_xxxxxxx, xxxxxx_xxxx=xxxxxxx + "/" + xxxx_xxx_xxxx, x=xxx_xxxxx_xxxxx_xxx),
x,
y,
z,
)
func_call_where_string_arg_has_method_call_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.".format("formatting")
),
)
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"
),
)
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")
),
)
class A:
def append(self):
if True:
xxxx.xxxxxxx.xxxxx( ('xxxxxxxxxx xxxx xx xxxxxx(%x) xx %x xxxx xx xxx %x.xx'
% (len(self) + 1,
xxxx.xxxxxxxxxx,
xxxx.xxxxxxxxxx))
+ (' %.3f (%s) to %.3f (%s).\n'
% (xxxx.xxxxxxxxx,
xxxx.xxxxxxxxxxxxxx(xxxx.xxxxxxxxx),
x,
xxxx.xxxxxxxxxxxxxx( xx)
)))
class A:
def foo():
some_func_call(
'xxxxxxxxxx',
(
"xx {xxxxxxxxxxx}/xxxxxxxxxxx.xxx xxxx.xxx && xxxxxx -x "
"\"xxxx xxxxxxx xxxxxx xxxx; xxxx xxxxxx_xxxxx xxxxxx xxxx; "
"xxxx.xxxx_xxxxxx(['xxxx.xxx'], xxxx.xxxxxxx().xxxxxxxxxx)\" "
),
None,
('xxxxxxxxxxx',),
),
class A:
def foo():
some_func_call(
(
"xx {xxxxxxxxxxx}/xxxxxxxxxxx.xxx xxxx.xxx && xxxxxx -x "
"xxxx, ('xxxxxxx xxxxxx xxxx, xxxx') xxxxxx_xxxxx xxxxxx xxxx; "
"xxxx.xxxx_xxxxxx(['xxxx.xxx'], xxxx.xxxxxxx().xxxxxxxxxx)\" "
),
None,
('xxxxxxxxxxx',),
),
xxxxxxx = { 'xx' : 'xxxx xxxxxxx xxxxxxxxx -x xxx -x /xxx/{0} -x xxx,xxx -xx {1} \
-xx {1} -xx xxx=xxx_xxxx,xxx_xx,xxx_xxx,xxx_xxxx,xxx_xx,xxx_xxx |\
xxxxxx -x xxxxxxxx -x xxxxxxxx -x',
'xx' : 'xxxx xxxxxxx xxxxxxxxx -x xxx -x /xxx/{0} -x xxx,xxx -xx {1} \
-xx {1} -xx xxx=xxx_xxxx_xxx_xxxx,xxx_xx_xxx_xxxx,xxx_xxxx_xxx_xxxx,\
xxx_xx_xxxx_xxxx,xxx_xxx_xxxx,xxx_xxx_xxxx xxxx=xxx | xxxxxx -x xxxxxxxx -x xxxxxxxx -x'
}
class A:
def foo(self):
if True:
xxxxx_xxxxxxxxxxxx('xxx xxxxxx xxx xxxxxxxxx.xx xx xxxxxxxx. xxx xxxxxxxxxxxxx.xx xxxxxxx '
+ 'xx xxxxxx xxxxxx xxxxxx xx xxxxxxx xxx xxx ${0} xx x xxxxxxxx xxxxx'.xxxxxx(xxxxxx_xxxxxx_xxx))
class A:
class B:
def foo():
row = {
'xxxxxxxxxxxxxxx' : xxxxxx_xxxxx_xxxx,
# 'xxxxxxxxxxxxxxxxxxxxxxx'
# 'xxxxxxxxxxxxxxxxxxxxxx'
# 'xxxxxxxxxxxxxxxxxx'
# 'xxxxxxxxxxxxxxxxx'
'xxxxxxxxxx' : xxxxx_xxxxx,
}
class A:
def xxxx_xxx_xx_xxxxxxxxxx_xxxx_xxxxxxxxx(xxxx):
xxxxxxxx = [
xxxxxxxxxxxxxxxx(
'xxxx',
xxxxxxxxxxx={
'xxxx' : 1.0,
},
xxxxxx={'xxxxxx 1' : xxxxxx(xxxx='xxxxxx 1', xxxxxx=600.0)},
xxxxxxxx_xxxxxxx=0.0,
),
xxxxxxxxxxxxxxxx(
'xxxxxxx',
xxxxxxxxxxx={
'xxxx' : 1.0,
},
xxxxxx={'xxxxxx 1' : xxxxxx(xxxx='xxxxxx 1', xxxxxx=200.0)},
xxxxxxxx_xxxxxxx=0.0,
),
xxxxxxxxxxxxxxxx(
'xxxx',
),
]
some_dictionary = {
'xxxxx006': ['xxx-xxx xxxxx3xxxx1xx2xxxxxxxxxxxxxx0xx6xxxxxxxxxx2xxxxxx9xxxxxxxxxx0xxxxx1xxx2x/xx9xx6+x+xxxxxxxxxxxxxx4xxxxxxxxxxxxxxxxxxxxx43xxx2xx2x4x++xxx6xxxxxxxxx+xxxxx/xx9x+xxxxxxxxxxxxxx8x15xxxxxxxxxxxxxxxxx82xx/xxxxxxxxxxxxxx/x5xxxxxxxxxxxxxx6xxxxxx74x4/xxx4x+xxxxxxxxx2xxxxxxxx87xxxxx4xxxxxxxx3xx0xxxxx4xxx1xx9xx5xxxxxxx/xxxxx5xx6xx4xxxx1x/x2xxxxxxxxxxxx64xxxxxxx1x0xx5xxxxxxxxxxxxxx== xxxxx000 xxxxxxxxxx\n',
'xxx-xxx xxxxx3xxxx1xx2xxxxxxxxxxxxxx6xxxxxxxxxxxxxx9xxxxxxxxxxxxx3xxx9xxxxxxxxxxxxxxxx0xxxxxxxxxxxxxxxxx2xxxx2xxx6xxxxx/xx54xxxxxxxxx4xxx3xxxxxx9xx3xxxxx39xxxxxxxxx5xx91xxxx7xxxxxx8xxxxxxxxxxxxxxxx9xxx93xxxxxxxxxxxxxxxxx7xxx8xx8xx4/x1xxxxx1x3xxxxxxxxxxxxx3xxxxxx9xx4xx4x7xxxxxxxxxxxxx1xxxxxxxxx7xxxxxxxxxxxxxx4xx6xxxxxxxxx9xxx7xxxx2xxxxxxxxxxxxxxxxxxxxxx8xxxxxxxxxxxxxxxxxxxx6xx== xxxxx010 xxxxxxxxxx\n'],
'xxxxx016': ['xxx-xxx xxxxx3xxxx1xx2xxxxxxxxxxxxxx0xx6xxxxxxxxxx2xxxxxx9xxxxxxxxxx0xxxxx1xxx2x/xx9xx6+x+xxxxxxxxxxxxxx4xxxxxxxxxxxxxxxxxxxxx43xxx2xx2x4x++xxx6xxxxxxxxx+xxxxx/xx9x+xxxxxxxxxxxxxx8x15xxxxxxxxxxxxxxxxx82xx/xxxxxxxxxxxxxx/x5xxxxxxxxxxxxxx6xxxxxx74x4/xxx4x+xxxxxxxxx2xxxxxxxx87xxxxx4xxxxxxxx3xx0xxxxx4xxx1xx9xx5xxxxxxx/xxxxx5xx6xx4xxxx1x/x2xxxxxxxxxxxx64xxxxxxx1x0xx5xxxxxxxxxxxxxx== xxxxx000 xxxxxxxxxx\n',
'xxx-xxx xxxxx3xxxx1xx2xxxxxxxxxxxxxx6xxxxxxxxxxxxxx9xxxxxxxxxxxxx3xxx9xxxxxxxxxxxxxxxx0xxxxxxxxxxxxxxxxx2xxxx2xxx6xxxxx/xx54xxxxxxxxx4xxx3xxxxxx9xx3xxxxx39xxxxxxxxx5xx91xxxx7xxxxxx8xxxxxxxxxxxxxxxx9xxx93xxxxxxxxxxxxxxxxx7xxx8xx8xx4/x1xxxxx1x3xxxxxxxxxxxxx3xxxxxx9xx4xx4x7xxxxxxxxxxxxx1xxxxxxxxx7xxxxxxxxxxxxxx4xx6xxxxxxxxx9xxx7xxxx2xxxxxxxxxxxxxxxxxxxxxx8xxxxxxxxxxxxxxxxxxxx6xx== xxxxx010 xxxxxxxxxx\n']
}
def foo():
xxx_xxx = (
'xxxx xxx xxxxxxxx_xxxx xx "xxxxxxxxxx".'
'\n xxx: xxxxxx xxxxxxxx_xxxx=xxxxxxxxxx'
) # xxxx xxxxxxxxxx xxxx xx xxxx xx xxx xxxxxxxx xxxxxx xxxxx.
some_tuple = ("some string", "some string" " which should be joined")
some_commented_string = (
"This string is long but not so long that it needs hahahah toooooo be so greatttt" # This comment gets thrown to the top.
" {} that I just can't think of any more good words to say about it at"
" allllllllllll".format("ha") # comments here are fine
)
some_commented_string = (
"This string is long but not so long that it needs hahahah toooooo be so greatttt" # But these
" {} that I just can't think of any more good words to say about it at" # comments will stay
" allllllllllll".format("ha") # comments here are fine
)
lpar_and_rpar_have_comments = func_call( # LPAR Comment
"Long really ridiculous type of string that shouldn't really even exist at all. I mean commmme onnn!!!", # Comma Comment
) # RPAR Comment
cmd_fstring = (
f"sudo -E deluge-console info --detailed --sort-reverse=time_added "
f"{'' if ID is None else ID} | perl -nE 'print if /^{field}:/'"
)
cmd_fstring = f"sudo -E deluge-console info --detailed --sort-reverse=time_added {'' if ID is None else ID} | perl -nE 'print if /^{field}:/'"
cmd_fstring = f"sudo -E deluge-console info --detailed --sort-reverse=time_added {'{{}}' if ID is None else ID} | perl -nE 'print if /^{field}:/'"
cmd_fstring = f"sudo -E deluge-console info --detailed --sort-reverse=time_added {{'' if ID is None else ID}} | perl -nE 'print if /^{field}:/'"
fstring = f"This string really doesn't need to be an {{{{fstring}}}}, but this one most certainly, absolutely {does}."
fstring = (
f"We have to remember to escape {braces}."
" Like {these}."
f" But not {this}."
)
class A:
class B:
def foo():
st_error = STError(
f"This string ({string_leaf.value}) appears to be pointless (i.e. has"
" no parent)."
)
def foo():
user_regex = _lazy_re_compile(
r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*\Z" # dot-atom
r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"\Z)', # quoted-string
re.IGNORECASE)
def foo():
user_regex = _lazy_re_compile(
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # dot-atom
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', # quoted-string
xyz
)
def foo():
user_regex = _lazy_re_compile(
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # dot-atom
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', # quoted-string
xyz
)
class A:
class B:
def foo():
if not hasattr(module, name):
raise ValueError(
"Could not find object %s in %s.\n"
"Please note that you cannot serialize things like inner "
"classes. Please move the object into the main module "
"body to use migrations.\n"
"For more information, see "
"https://docs.djangoproject.com/en/%s/topics/migrations/#serializing-values"
% (name, module_name, get_docs_version()))
class A:
class B:
def foo():
if not hasattr(module, name):
raise ValueError(
"Could not find object %s in %s.\nPlease note that you cannot serialize things like inner classes. Please move the object into the main module body to use migrations.\nFor more information, see https://docs.djangoproject.com/en/%s/topics/migrations/#serializing-values"
% (name, module_name, get_docs_version()))
x = (
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
)
class Step(StepBase):
def who(self):
self.cmd = 'SR AAAA-CORRECT NAME IS {last_name} {first_name}{middle_name} {title}/P{passenger_association}'.format(
last_name=last_name,
first_name=first_name,
middle_name=middle_name,
title=title,
passenger_association=passenger_association,
)
# output
class A:
def foo():
result = type(message)("")
# Don't merge multiline (e.g. triple-quoted) strings.
def foo():
query = (
"""SELECT xxxxxxxxxxxxxxxxxxxx(xxx)"""
""" FROM xxxxxxxxxxxxxxxx WHERE xxxxxxxxxx AND xxx <> xxxxxxxxxxxxxx()"""
)
# There was a bug where tuples were being identified as long strings.
long_tuple = (
"Apple",
"Berry",
"Cherry",
"Dill",
"Evergreen",
"Fig",
"Grape",
"Harry",
"Iglu",
"Jaguar",
)
stupid_format_method_bug = (
"Some really long string that just so happens to be the {} {} to force the 'format'"
" method to hang over the line length boundary. This is pretty annoying.".format(
"perfect", "length"
)
)
class A:
def foo():
os.system(
"This is a regression test. xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx"
" xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx"
" xxxx.".format("xxxxxxxxxx", "xxxxxx", "xxxxxxxxxx")
)
class A:
def foo():
XXXXXXXXXXXX.append(
(
"xxx_xxxxxxxxxx(xxxxx={}, xxxx={}, xxxxx, xxxx_xxxx_xxxxxxxxxx={})"
.format(xxxxx, xxxx, xxxx_xxxx_xxxxxxxxxx),
my_var,
my_other_var,
)
)
class A:
class B:
def foo():
bar(
"[{}]: xxx_xxxxxxxxxx(xxxxx={}, xxxx={}, xxxxx={}"
" xxxx_xxxx_xxxxxxxxxx={}, xxxx={})".format(
xxxx._xxxxxxxxxxxxxx, xxxxx, xxxx, xxxx_xxxx_xxxxxxxxxx, xxxxxxx
),
varX,
varY,
varZ,
)
def foo(xxxx):
for (xxx_xxxx, _xxx_xxx, _xxx_xxxxx, xxx_xxxx) in xxxx:
for xxx in xxx_xxxx:
assert ("x" in xxx) or (xxx in xxx_xxx_xxxxx), (
"{0} xxxxxxx xx {1}, xxx {1} xx xxx xx xxxx xx xxx xxxx: xxx xxxx {2}"
.format(xxx_xxxx, xxx, xxxxxx.xxxxxxx(xxx_xxx_xxxxx))
)
class A:
def disappearing_comment():
return (
( # xx -x xxxxxxx xx xxx xxxxxxx.
"{{xxx_xxxxxxxxxx_xxxxxxxx}} xxx xxxx {} {{xxxx}} >&2".format(
"{xxxx} {xxxxxx}"
if xxxxx.xx_xxxxxxxxxx
else ( # Disappearing Comment
"--xxxxxxx --xxxxxx=x --xxxxxx-xxxxx=xxxxxx"
" --xxxxxx-xxxx=xxxxxxxxxxx.xxx"
)
)
),
(x, y, z),
)
class A:
class B:
def foo():
xxxxx_xxxx(
xx,
"\t"
"@xxxxxx '{xxxx_xxx}\t' > {xxxxxx_xxxx}.xxxxxxx;"
"{xxxx_xxx} >> {xxxxxx_xxxx}.xxxxxxx 2>&1; xx=$$?;"
"xxxx $$xx".format(
xxxx_xxx=xxxx_xxxxxxx,
xxxxxx_xxxx=xxxxxxx + "/" + xxxx_xxx_xxxx,
x=xxx_xxxxx_xxxxx_xxx,
),
x,
y,
z,
)
func_call_where_string_arg_has_method_call_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.".format("formatting"),
)
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",
)
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"),
)
class A:
def append(self):
if True:
xxxx.xxxxxxx.xxxxx(
"xxxxxxxxxx xxxx xx xxxxxx(%x) xx %x xxxx xx xxx %x.xx"
% (len(self) + 1, xxxx.xxxxxxxxxx, xxxx.xxxxxxxxxx)
+ " %.3f (%s) to %.3f (%s).\n"
% (
xxxx.xxxxxxxxx,
xxxx.xxxxxxxxxxxxxx(xxxx.xxxxxxxxx),
x,
xxxx.xxxxxxxxxxxxxx(xx),
)
)
class A:
def foo():
some_func_call(
"xxxxxxxxxx",
"xx {xxxxxxxxxxx}/xxxxxxxxxxx.xxx xxxx.xxx && xxxxxx -x "
'"xxxx xxxxxxx xxxxxx xxxx; xxxx xxxxxx_xxxxx xxxxxx xxxx; '
"xxxx.xxxx_xxxxxx(['xxxx.xxx'], xxxx.xxxxxxx().xxxxxxxxxx)\" ",
None,
("xxxxxxxxxxx",),
),
class A:
def foo():
some_func_call(
"xx {xxxxxxxxxxx}/xxxxxxxxxxx.xxx xxxx.xxx && xxxxxx -x "
"xxxx, ('xxxxxxx xxxxxx xxxx, xxxx') xxxxxx_xxxxx xxxxxx xxxx; "
"xxxx.xxxx_xxxxxx(['xxxx.xxx'], xxxx.xxxxxxx().xxxxxxxxxx)\" ",
None,
("xxxxxxxxxxx",),
),
xxxxxxx = {
"xx": (
"xxxx xxxxxxx xxxxxxxxx -x xxx -x /xxx/{0} -x xxx,xxx -xx {1} -xx {1} -xx"
" xxx=xxx_xxxx,xxx_xx,xxx_xxx,xxx_xxxx,xxx_xx,xxx_xxx | xxxxxx -x xxxxxxxx -x"
" xxxxxxxx -x"
),
"xx": (
"xxxx xxxxxxx xxxxxxxxx -x xxx -x /xxx/{0} -x xxx,xxx -xx {1} -xx {1} -xx"
" xxx=xxx_xxxx_xxx_xxxx,xxx_xx_xxx_xxxx,xxx_xxxx_xxx_xxxx,xxx_xx_xxxx_xxxx,xxx_xxx_xxxx,xxx_xxx_xxxx"
" xxxx=xxx | xxxxxx -x xxxxxxxx -x xxxxxxxx -x"
),
}
class A:
def foo(self):
if True:
xxxxx_xxxxxxxxxxxx(
"xxx xxxxxx xxx xxxxxxxxx.xx xx xxxxxxxx. xxx xxxxxxxxxxxxx.xx"
" xxxxxxx "
+ "xx xxxxxx xxxxxx xxxxxx xx xxxxxxx xxx xxx ${0} xx x xxxxxxxx xxxxx"
.xxxxxx(xxxxxx_xxxxxx_xxx)
)
class A:
class B:
def foo():
row = {
"xxxxxxxxxxxxxxx": xxxxxx_xxxxx_xxxx,
# 'xxxxxxxxxxxxxxxxxxxxxxx'
# 'xxxxxxxxxxxxxxxxxxxxxx'
# 'xxxxxxxxxxxxxxxxxx'
# 'xxxxxxxxxxxxxxxxx'
"xxxxxxxxxx": xxxxx_xxxxx,
}
class A:
def xxxx_xxx_xx_xxxxxxxxxx_xxxx_xxxxxxxxx(xxxx):
xxxxxxxx = [
xxxxxxxxxxxxxxxx(
"xxxx",
xxxxxxxxxxx={"xxxx": 1.0,},
xxxxxx={"xxxxxx 1": xxxxxx(xxxx="xxxxxx 1", xxxxxx=600.0)},
xxxxxxxx_xxxxxxx=0.0,
),
xxxxxxxxxxxxxxxx(
"xxxxxxx",
xxxxxxxxxxx={"xxxx": 1.0,},
xxxxxx={"xxxxxx 1": xxxxxx(xxxx="xxxxxx 1", xxxxxx=200.0)},
xxxxxxxx_xxxxxxx=0.0,
),
xxxxxxxxxxxxxxxx("xxxx",),
]
some_dictionary = {
"xxxxx006": [
"xxx-xxx"
" xxxxx3xxxx1xx2xxxxxxxxxxxxxx0xx6xxxxxxxxxx2xxxxxx9xxxxxxxxxx0xxxxx1xxx2x/xx9xx6+x+xxxxxxxxxxxxxx4xxxxxxxxxxxxxxxxxxxxx43xxx2xx2x4x++xxx6xxxxxxxxx+xxxxx/xx9x+xxxxxxxxxxxxxx8x15xxxxxxxxxxxxxxxxx82xx/xxxxxxxxxxxxxx/x5xxxxxxxxxxxxxx6xxxxxx74x4/xxx4x+xxxxxxxxx2xxxxxxxx87xxxxx4xxxxxxxx3xx0xxxxx4xxx1xx9xx5xxxxxxx/xxxxx5xx6xx4xxxx1x/x2xxxxxxxxxxxx64xxxxxxx1x0xx5xxxxxxxxxxxxxx=="
" xxxxx000 xxxxxxxxxx\n",
"xxx-xxx"
" xxxxx3xxxx1xx2xxxxxxxxxxxxxx6xxxxxxxxxxxxxx9xxxxxxxxxxxxx3xxx9xxxxxxxxxxxxxxxx0xxxxxxxxxxxxxxxxx2xxxx2xxx6xxxxx/xx54xxxxxxxxx4xxx3xxxxxx9xx3xxxxx39xxxxxxxxx5xx91xxxx7xxxxxx8xxxxxxxxxxxxxxxx9xxx93xxxxxxxxxxxxxxxxx7xxx8xx8xx4/x1xxxxx1x3xxxxxxxxxxxxx3xxxxxx9xx4xx4x7xxxxxxxxxxxxx1xxxxxxxxx7xxxxxxxxxxxxxx4xx6xxxxxxxxx9xxx7xxxx2xxxxxxxxxxxxxxxxxxxxxx8xxxxxxxxxxxxxxxxxxxx6xx=="
" xxxxx010 xxxxxxxxxx\n",
],
"xxxxx016": [
"xxx-xxx"
" xxxxx3xxxx1xx2xxxxxxxxxxxxxx0xx6xxxxxxxxxx2xxxxxx9xxxxxxxxxx0xxxxx1xxx2x/xx9xx6+x+xxxxxxxxxxxxxx4xxxxxxxxxxxxxxxxxxxxx43xxx2xx2x4x++xxx6xxxxxxxxx+xxxxx/xx9x+xxxxxxxxxxxxxx8x15xxxxxxxxxxxxxxxxx82xx/xxxxxxxxxxxxxx/x5xxxxxxxxxxxxxx6xxxxxx74x4/xxx4x+xxxxxxxxx2xxxxxxxx87xxxxx4xxxxxxxx3xx0xxxxx4xxx1xx9xx5xxxxxxx/xxxxx5xx6xx4xxxx1x/x2xxxxxxxxxxxx64xxxxxxx1x0xx5xxxxxxxxxxxxxx=="
" xxxxx000 xxxxxxxxxx\n",
"xxx-xxx"
" xxxxx3xxxx1xx2xxxxxxxxxxxxxx6xxxxxxxxxxxxxx9xxxxxxxxxxxxx3xxx9xxxxxxxxxxxxxxxx0xxxxxxxxxxxxxxxxx2xxxx2xxx6xxxxx/xx54xxxxxxxxx4xxx3xxxxxx9xx3xxxxx39xxxxxxxxx5xx91xxxx7xxxxxx8xxxxxxxxxxxxxxxx9xxx93xxxxxxxxxxxxxxxxx7xxx8xx8xx4/x1xxxxx1x3xxxxxxxxxxxxx3xxxxxx9xx4xx4x7xxxxxxxxxxxxx1xxxxxxxxx7xxxxxxxxxxxxxx4xx6xxxxxxxxx9xxx7xxxx2xxxxxxxxxxxxxxxxxxxxxx8xxxxxxxxxxxxxxxxxxxx6xx=="
" xxxxx010 xxxxxxxxxx\n",
],
}
def foo():
xxx_xxx = ( # xxxx xxxxxxxxxx xxxx xx xxxx xx xxx xxxxxxxx xxxxxx xxxxx.
'xxxx xxx xxxxxxxx_xxxx xx "xxxxxxxxxx".\n xxx: xxxxxx xxxxxxxx_xxxx=xxxxxxxxxx'
)
some_tuple = ("some string", "some string which should be joined")
some_commented_string = ( # This comment gets thrown to the top.
"This string is long but not so long that it needs hahahah toooooo be so greatttt"
" {} that I just can't think of any more good words to say about it at"
" allllllllllll".format("ha") # comments here are fine
)
some_commented_string = (
"This string is long but not so long that it needs hahahah toooooo be so greatttt" # But these
" {} that I just can't think of any more good words to say about it at" # comments will stay
" allllllllllll".format("ha") # comments here are fine
)
lpar_and_rpar_have_comments = func_call( # LPAR Comment
"Long really ridiculous type of string that shouldn't really even exist at all. I"
" mean commmme onnn!!!", # Comma Comment
) # RPAR Comment
cmd_fstring = (
"sudo -E deluge-console info --detailed --sort-reverse=time_added "
f"{'' if ID is None else ID} | perl -nE 'print if /^{field}:/'"
)
cmd_fstring = (
"sudo -E deluge-console info --detailed --sort-reverse=time_added"
f" {'' if ID is None else ID} | perl -nE 'print if /^{field}:/'"
)
cmd_fstring = (
"sudo -E deluge-console info --detailed --sort-reverse=time_added"
f" {'{{}}' if ID is None else ID} | perl -nE 'print if /^{field}:/'"
)
cmd_fstring = (
"sudo -E deluge-console info --detailed --sort-reverse=time_added {'' if ID is"
f" None else ID}} | perl -nE 'print if /^{field}:/'"
)
fstring = (
"This string really doesn't need to be an {{fstring}}, but this one most"
f" certainly, absolutely {does}."
)
fstring = f"We have to remember to escape {braces}. Like {{these}}. But not {this}."
class A:
class B:
def foo():
st_error = STError(
f"This string ({string_leaf.value}) appears to be pointless (i.e. has"
" no parent)."
)
def foo():
user_regex = _lazy_re_compile(
r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*\Z" # dot-atom
r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"\Z)', # quoted-string
re.IGNORECASE,
)
def foo():
user_regex = _lazy_re_compile(
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # dot-atom
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", # quoted-string
xyz,
)
def foo():
user_regex = _lazy_re_compile(
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # dot-atom
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", # quoted-string
xyz,
)
class A:
class B:
def foo():
if not hasattr(module, name):
raise ValueError(
"Could not find object %s in %s.\n"
"Please note that you cannot serialize things like inner "
"classes. Please move the object into the main module "
"body to use migrations.\n"
"For more information, see "
"https://docs.djangoproject.com/en/%s/topics/migrations/#serializing-values"
% (name, module_name, get_docs_version())
)
class A:
class B:
def foo():
if not hasattr(module, name):
raise ValueError(
"Could not find object %s in %s.\nPlease note that you cannot"
" serialize things like inner classes. Please move the object into"
" the main module body to use migrations.\nFor more information,"
" see https://docs.djangoproject.com/en/%s/topics/migrations/#serializing-values"
% (name, module_name, get_docs_version())
)
x = (
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
)
class Step(StepBase):
def who(self):
self.cmd = (
"SR AAAA-CORRECT NAME IS {last_name} {first_name}{middle_name}"
" {title}/P{passenger_association}".format(
last_name=last_name,
first_name=first_name,
middle_name=middle_name,
title=title,
passenger_association=passenger_association,
)
)

View File

@ -79,12 +79,7 @@
r'Tricky "quote'
r"Not-so-tricky \"quote"
rf"{yay}"
"\n\
The \"quick\"\n\
brown fox\n\
jumps over\n\
the 'lazy' dog.\n\
"
"\nThe \"quick\"\nbrown fox\njumps over\nthe 'lazy' dog.\n"
re.compile(r'[\\"]')
"x = ''; y = \"\""
"x = '''; y = \"\""
@ -104,4 +99,4 @@
f'\'{z}\' {y * " "}'
f"{y * x} '{z}'"
"'{z}' {y * \" \"}"
"{y * x} '{z}'"
"{y * x} '{z}'"

View File

@ -243,8 +243,8 @@ def test_piping(self) -> None:
def test_piping_diff(self) -> None:
diff_header = re.compile(
rf"(STDIN|STDOUT)\t\d\d\d\d-\d\d-\d\d "
rf"\d\d:\d\d:\d\d\.\d\d\d\d\d\d \+\d\d\d\d"
rf"(STDIN|STDOUT)\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\.\d\d\d\d\d\d "
rf"\+\d\d\d\d"
)
source, _ = read_data("expression.py")
expected, _ = read_data("expression.diff")
@ -333,7 +333,7 @@ def test_expression_diff(self) -> None:
tmp_file = Path(black.dump_to_file(source))
diff_header = re.compile(
rf"{re.escape(str(tmp_file))}\t\d\d\d\d-\d\d-\d\d "
rf"\d\d:\d\d:\d\d\.\d\d\d\d\d\d \+\d\d\d\d"
r"\d\d:\d\d:\d\d\.\d\d\d\d\d\d \+\d\d\d\d"
)
try:
result = BlackRunner().invoke(black.main, ["--diff", str(tmp_file)])
@ -346,9 +346,9 @@ def test_expression_diff(self) -> None:
if expected != actual:
dump = black.dump_to_file(actual)
msg = (
f"Expected diff isn't equal to the actual. If you made changes "
f"to expression.py and this is an anticipated difference, "
f"overwrite tests/data/expression.diff with {dump}"
"Expected diff isn't equal to the actual. If you made changes to"
" expression.py and this is an anticipated difference, overwrite"
f" tests/data/expression.diff with {dump}"
)
self.assertEqual(expected, actual, msg)
@ -386,10 +386,37 @@ def test_string_quotes(self) -> None:
black.assert_stable(source, actual, black.FileMode())
mode = black.FileMode(string_normalization=False)
not_normalized = fs(source, mode=mode)
self.assertFormatEqual(source, not_normalized)
self.assertFormatEqual(source.replace("\\\n", ""), not_normalized)
black.assert_equivalent(source, not_normalized)
black.assert_stable(source, not_normalized, mode=mode)
@patch("black.dump_to_file", dump_to_stderr)
def test_long_strings(self) -> None:
"""Tests for splitting long strings."""
source, expected = read_data("long_strings")
actual = fs(source)
self.assertFormatEqual(expected, actual)
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, black.FileMode())
@patch("black.dump_to_file", dump_to_stderr)
def test_long_strings__edge_case(self) -> None:
"""Edge-case tests for splitting long strings."""
source, expected = read_data("long_strings__edge_case")
actual = fs(source)
self.assertFormatEqual(expected, actual)
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, black.FileMode())
@patch("black.dump_to_file", dump_to_stderr)
def test_long_strings__regression(self) -> None:
"""Regression tests for splitting long strings."""
source, expected = read_data("long_strings__regression")
actual = fs(source)
self.assertFormatEqual(expected, actual)
black.assert_equivalent(source, actual)
black.assert_stable(source, actual, black.FileMode())
@patch("black.dump_to_file", dump_to_stderr)
def test_slices(self) -> None:
source, expected = read_data("slices")
@ -746,8 +773,8 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(err_lines[-1], "error: cannot format e1: boom")
self.assertEqual(
unstyle(str(report)),
"1 file reformatted, 2 files left unchanged, "
"1 file failed to reformat.",
"1 file reformatted, 2 files left unchanged, 1 file failed to"
" reformat.",
)
self.assertEqual(report.return_code, 123)
report.done(Path("f3"), black.Changed.YES)
@ -756,8 +783,8 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(out_lines[-1], "reformatted f3")
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 2 files left unchanged, "
"1 file failed to reformat.",
"2 files reformatted, 2 files left unchanged, 1 file failed to"
" reformat.",
)
self.assertEqual(report.return_code, 123)
report.failed(Path("e2"), "boom")
@ -766,8 +793,8 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(err_lines[-1], "error: cannot format e2: boom")
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 2 files left unchanged, "
"2 files failed to reformat.",
"2 files reformatted, 2 files left unchanged, 2 files failed to"
" reformat.",
)
self.assertEqual(report.return_code, 123)
report.path_ignored(Path("wat"), "no match")
@ -776,8 +803,8 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(out_lines[-1], "wat ignored: no match")
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 2 files left unchanged, "
"2 files failed to reformat.",
"2 files reformatted, 2 files left unchanged, 2 files failed to"
" reformat.",
)
self.assertEqual(report.return_code, 123)
report.done(Path("f4"), black.Changed.NO)
@ -786,22 +813,22 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(out_lines[-1], "f4 already well formatted, good job.")
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 3 files left unchanged, "
"2 files failed to reformat.",
"2 files reformatted, 3 files left unchanged, 2 files failed to"
" reformat.",
)
self.assertEqual(report.return_code, 123)
report.check = True
self.assertEqual(
unstyle(str(report)),
"2 files would be reformatted, 3 files would be left unchanged, "
"2 files would fail to reformat.",
"2 files would be reformatted, 3 files would be left unchanged, 2 files"
" would fail to reformat.",
)
report.check = False
report.diff = True
self.assertEqual(
unstyle(str(report)),
"2 files would be reformatted, 3 files would be left unchanged, "
"2 files would fail to reformat.",
"2 files would be reformatted, 3 files would be left unchanged, 2 files"
" would fail to reformat.",
)
def test_report_quiet(self) -> None:
@ -843,8 +870,8 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(err_lines[-1], "error: cannot format e1: boom")
self.assertEqual(
unstyle(str(report)),
"1 file reformatted, 2 files left unchanged, "
"1 file failed to reformat.",
"1 file reformatted, 2 files left unchanged, 1 file failed to"
" reformat.",
)
self.assertEqual(report.return_code, 123)
report.done(Path("f3"), black.Changed.YES)
@ -852,8 +879,8 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(len(err_lines), 1)
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 2 files left unchanged, "
"1 file failed to reformat.",
"2 files reformatted, 2 files left unchanged, 1 file failed to"
" reformat.",
)
self.assertEqual(report.return_code, 123)
report.failed(Path("e2"), "boom")
@ -862,8 +889,8 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(err_lines[-1], "error: cannot format e2: boom")
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 2 files left unchanged, "
"2 files failed to reformat.",
"2 files reformatted, 2 files left unchanged, 2 files failed to"
" reformat.",
)
self.assertEqual(report.return_code, 123)
report.path_ignored(Path("wat"), "no match")
@ -871,8 +898,8 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(len(err_lines), 2)
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 2 files left unchanged, "
"2 files failed to reformat.",
"2 files reformatted, 2 files left unchanged, 2 files failed to"
" reformat.",
)
self.assertEqual(report.return_code, 123)
report.done(Path("f4"), black.Changed.NO)
@ -880,22 +907,22 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(len(err_lines), 2)
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 3 files left unchanged, "
"2 files failed to reformat.",
"2 files reformatted, 3 files left unchanged, 2 files failed to"
" reformat.",
)
self.assertEqual(report.return_code, 123)
report.check = True
self.assertEqual(
unstyle(str(report)),
"2 files would be reformatted, 3 files would be left unchanged, "
"2 files would fail to reformat.",
"2 files would be reformatted, 3 files would be left unchanged, 2 files"
" would fail to reformat.",
)
report.check = False
report.diff = True
self.assertEqual(
unstyle(str(report)),
"2 files would be reformatted, 3 files would be left unchanged, "
"2 files would fail to reformat.",
"2 files would be reformatted, 3 files would be left unchanged, 2 files"
" would fail to reformat.",
)
def test_report_normal(self) -> None:
@ -939,8 +966,8 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(err_lines[-1], "error: cannot format e1: boom")
self.assertEqual(
unstyle(str(report)),
"1 file reformatted, 2 files left unchanged, "
"1 file failed to reformat.",
"1 file reformatted, 2 files left unchanged, 1 file failed to"
" reformat.",
)
self.assertEqual(report.return_code, 123)
report.done(Path("f3"), black.Changed.YES)
@ -949,8 +976,8 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(out_lines[-1], "reformatted f3")
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 2 files left unchanged, "
"1 file failed to reformat.",
"2 files reformatted, 2 files left unchanged, 1 file failed to"
" reformat.",
)
self.assertEqual(report.return_code, 123)
report.failed(Path("e2"), "boom")
@ -959,8 +986,8 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(err_lines[-1], "error: cannot format e2: boom")
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 2 files left unchanged, "
"2 files failed to reformat.",
"2 files reformatted, 2 files left unchanged, 2 files failed to"
" reformat.",
)
self.assertEqual(report.return_code, 123)
report.path_ignored(Path("wat"), "no match")
@ -968,8 +995,8 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(len(err_lines), 2)
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 2 files left unchanged, "
"2 files failed to reformat.",
"2 files reformatted, 2 files left unchanged, 2 files failed to"
" reformat.",
)
self.assertEqual(report.return_code, 123)
report.done(Path("f4"), black.Changed.NO)
@ -977,22 +1004,22 @@ def err(msg: str, **kwargs: Any) -> None:
self.assertEqual(len(err_lines), 2)
self.assertEqual(
unstyle(str(report)),
"2 files reformatted, 3 files left unchanged, "
"2 files failed to reformat.",
"2 files reformatted, 3 files left unchanged, 2 files failed to"
" reformat.",
)
self.assertEqual(report.return_code, 123)
report.check = True
self.assertEqual(
unstyle(str(report)),
"2 files would be reformatted, 3 files would be left unchanged, "
"2 files would fail to reformat.",
"2 files would be reformatted, 3 files would be left unchanged, 2 files"
" would fail to reformat.",
)
report.check = False
report.diff = True
self.assertEqual(
unstyle(str(report)),
"2 files would be reformatted, 3 files would be left unchanged, "
"2 files would fail to reformat.",
"2 files would be reformatted, 3 files would be left unchanged, 2 files"
" would fail to reformat.",
)
def test_lib2to3_parse(self) -> None:
@ -1753,8 +1780,7 @@ async def test_blackd_pyi(self) -> None:
@unittest_run_loop
async def test_blackd_diff(self) -> None:
diff_header = re.compile(
rf"(In|Out)\t\d\d\d\d-\d\d-\d\d "
rf"\d\d:\d\d:\d\d\.\d\d\d\d\d\d \+\d\d\d\d"
rf"(In|Out)\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\.\d\d\d\d\d\d \+\d\d\d\d"
)
source, _ = read_data("blackd_diff.py")