All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 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."
3 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."
8 "This is a really long string inside of a print statement with extra arguments attached at the end of it.",
15 "This is a really long string inside of a print statement with no extra arguments attached at the end of it."
19 "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.",
20 "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.",
24 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.",
25 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.",
29 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.",
30 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.",
34 "A long and ridiculous {}".format(
36 ): "This is a really really really long string that has to go i,side of a dictionary. It is soooo bad.",
38 "calling", "some", "stuff"
39 ): "This is a really really really long string that has to go inside of a dictionary. It is {soooo} bad (#{x}).".format(
46 ): "This is a really really really long string that has to go inside of a dictionary. It is %s bad (#%d)."
52 my_kwarg="Long keyword strings also need to be wrapped, but they will probably need to be handled a little bit differently.",
56 "But what should happen when code has already been formatted but in the wrong way? Like"
57 " with a space at the end instead of the beginning. Or what about when it is split too soon?"
61 "But what should happen when code has already "
62 "been formatted but in the wrong way? Like "
63 "with a space at the end instead of the "
64 "beginning. Or what about when it is split too "
65 "soon? In the case of a split that is too "
66 "short, black will try to honer the custom "
71 "What if we have inline comments on " # First Comment
72 "each line of a bad split? In that " # Second Comment
73 "case, we should just leave it alone." # Third Comment
77 "But what should happen when code has already "
78 "been formatted but in the wrong way? Like "
79 "with a space at the end instead of the "
80 "beginning. Or what about when it is split too "
81 "soon? In the case of a split that is too "
82 "short, black will try to honer the custom "
93 long_string_kwarg="But what should happen when code has already been formatted but in the wrong way? Like "
94 "with a space at the end instead of the beginning. Or what about when it is split too "
100 "But what should happen when code has already "
101 r"been formatted but in the wrong way? Like "
102 "with a space at the end instead of the "
103 r"beginning. Or what about when it is split too "
104 r"soon? In the case of a split that is too "
105 "short, black will try to honer the custom "
113 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."
115 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(
119 fmt_string2 = "But what about when the string is {} but {}".format(
121 "the method call is really really really really really really really really long?",
125 "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."
126 % ("formatting", "code")
129 old_fmt_string2 = "This is a %s %s %s %s" % (
130 "really really really really really",
132 "way to format strings!",
133 "Use f-strings instead!",
137 "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"
139 "really really really really really",
141 "way to format strings!",
142 "Use f-strings instead!",
146 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."
148 fstring_with_no_fexprs = f"Some regular string that needs to get split certainly but is NOT an fstring by any means whatsoever."
150 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.
152 arg_comment_string = print(
153 "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.
160 pragma_comment_string1 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa: E501
162 pragma_comment_string2 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa
164 """This is a really really really long triple quote string and it should not be touched."""
166 triple_quote_string = """This is a really really really long triple quote string assignment and it should not be touched."""
169 some_type_of_boolean_expression
170 ), "Followed by a really really really long string that is used to provide context to the AssertionError exception."
173 some_type_of_boolean_expression
174 ), "Followed by a really really really long string that is used to provide context to the AssertionError exception, which uses dynamic string {}.".format(
178 assert some_type_of_boolean_expression, (
179 "Followed by a really really really long string that is used to provide context to the AssertionError exception, which uses dynamic string %s."
183 assert some_type_of_boolean_expression, (
184 "Followed by a really really really long string that is used to provide context to the AssertionError exception, which uses dynamic %s %s."
185 % ("string", "formatting")
189 "With a reallly generic name and with a really really long string that is, at some point down the line, "
191 + " to a variable and then added to another string."
195 "With a reallly generic name and with a really really long string that is, at some point down the line, "
197 + " 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.",
198 "and a second argument",
202 return "A really really really really really really really really really really really really really long {} {}".format(
207 "This is a really long string argument to a function that has a trailing comma which should NOT be there.",
211 "This is a really long string argument to a function that has a trailing comma which should NOT be there.", # comment after comma
216 "This is a really long string argument to a function that has a trailing comma"
217 " which should NOT be there."
223 "This is a really long string argument to a function that has a trailing comma"
224 " which should NOT be there."
225 ), # comment after comma
228 func_with_bad_parens_that_wont_fit_in_one_line(
229 ("short string that should have parens stripped"), x, y, z
232 func_with_bad_parens_that_wont_fit_in_one_line(
233 x, y, ("short string that should have parens stripped"), z
236 func_with_bad_parens(
237 ("short string that should have parens stripped"),
243 func_with_bad_parens(
246 ("short string that should have parens stripped"),
250 annotated_variable: Final = (
255 + "using the '+' operator."
257 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."
258 annotated_variable: Literal[
260 ] = "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."
262 backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\"
263 backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\\\"
264 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...\\\\\\"
266 short_string = "Hi" " there."
268 func_call(short_string=("Hi" " there."))
270 raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
274 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."
277 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."
279 long_unmergable_string_with_pragma = (
280 "This is a really long string that can't be merged because it has a likely pragma at the end" # type: ignore
284 long_unmergable_string_with_pragma = (
285 "This is a really long string that can't be merged because it has a likely pragma at the end" # noqa
289 long_unmergable_string_with_pragma = (
290 "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