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."
9 print('This is a really long string inside of a print statement with extra arguments attached at the end of it.', x, y, z)
11 print("This is a really long string inside of a print statement with no extra arguments attached at the end of it.")
13 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."}
15 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."}
17 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."}
19 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)}
21 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.")
24 'But what should happen when code has already been formatted but in the wrong way? Like'
25 " with a space at the end instead of the beginning. Or what about when it is split too soon?"
28 bad_split2 = "But what should happen when code has already " \
29 "been formatted but in the wrong way? Like " \
30 "with a space at the end instead of the " \
31 "beginning. Or what about when it is split too " \
32 "soon? In the case of a split that is too " \
33 "short, black will try to honer the custom " \
37 "What if we have inline comments on " # First Comment
38 "each line of a bad split? In that " # Second Comment
39 "case, we should just leave it alone." # Third Comment
43 "But what should happen when code has already "
44 "been formatted but in the wrong way? Like "
45 "with a space at the end instead of the "
46 "beginning. Or what about when it is split too "
47 "soon? In the case of a split that is too "
48 "short, black will try to honer the custom "
55 long_string_kwarg="But what should happen when code has already been formatted but in the wrong way? Like "
56 "with a space at the end instead of the beginning. Or what about when it is split too "
62 "But what should happen when code has already "
63 r"been formatted but in the wrong way? Like "
64 "with a space at the end instead of the "
65 r"beginning. Or what about when it is split too "
66 r"soon? In the case of a split that is too "
67 "short, black will try to honer the custom "
75 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."
77 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")
79 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?")
81 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")
83 old_fmt_string2 = "This is a %s %s %s %s" % ("really really really really really", "old", "way to format strings!", "Use f-strings instead!")
85 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!")
87 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."
89 fstring_with_no_fexprs = f"Some regular string that needs to get split certainly but is NOT an fstring by any means whatsoever."
91 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.
93 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.
94 "Arg #2", "Arg #3", "Arg #4", "Arg #5")
96 pragma_comment_string1 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa: E501
98 pragma_comment_string2 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa
100 """This is a really really really long triple quote string and it should not be touched."""
102 triple_quote_string = """This is a really really really long triple quote string assignment and it should not be touched."""
104 assert some_type_of_boolean_expression, "Followed by a really really really long string that is used to provide context to the AssertionError exception."
106 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")
108 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"
110 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")
112 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.")
114 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)
116 return "A really really really really really really really really really really really really really long {} {}".format("return", "value")
119 "This is a really long string argument to a function that has a trailing comma which should NOT be there.",
123 "This is a really long string argument to a function that has a trailing comma which should NOT be there.", # comment after comma
128 "This is a really long string argument to a function that has a trailing comma"
129 " which should NOT be there."
135 "This is a really long string argument to a function that has a trailing comma"
136 " which should NOT be there."
137 ), # comment after comma
140 func_with_bad_parens(
141 ("short string that should have parens stripped"),
147 func_with_bad_parens(
150 ("short string that should have parens stripped"),
154 annotated_variable: Final = "This is a large " + STRING + " that has been " + CONCATENATED + "using the '+' operator."
155 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."
156 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."
158 backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\"
159 backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\\\"
160 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...\\\\\\"
174 raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
177 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."
179 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."
181 long_unmergable_string_with_pragma = (
182 "This is a really long string that can't be merged because it has a likely pragma at the end" # type: ignore
186 long_unmergable_string_with_pragma = (
187 "This is a really long string that can't be merged because it has a likely pragma at the end" # noqa
191 long_unmergable_string_with_pragma = (
192 "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
201 "This is a really long string that can't possibly be expected to fit all together"
202 " on one line. In fact it may even take up three or more lines... like four or"
203 " five... but probably just three."
207 "This is a really long string that can't possibly be expected to fit all together"
208 " on one line. In fact it may even take up three or more lines... like four or"
209 " five... but probably just three."
215 "This is a really long string inside of a print statement with extra arguments"
216 " attached at the end of it.",
223 "This is a really long string inside of a print statement with no extra arguments"
224 " attached at the end of it."
229 "This is a really long string that can't possibly be expected to fit all"
230 " together on one line. Also it is inside a dictionary, so formatting is more"
234 "This is another really really (not really) long string that also can't be"
235 " expected to fit on one line and is, like the other string, inside a"
242 "This is a really long string that can't possibly be expected to fit all"
243 " together on one line. Also it is inside a dictionary, so formatting is more"
247 "This is another really really (not really) long string that also can't be"
248 " expected to fit on one line and is, like the other string, inside a"
255 "This is a really long string that can't possibly be expected to fit all"
256 " together on one line. Also it is inside a dictionary, so formatting is more"
260 "This is another really really (not really) long string that also can't be"
261 " expected to fit on one line and is, like the other string, inside a"
267 "A long and ridiculous {}".format(string_key): (
268 "This is a really really really long string that has to go i,side of a"
269 " dictionary. It is soooo bad."
271 some_func("calling", "some", "stuff"): (
272 "This is a really really really long string that has to go inside of a"
273 " dictionary. It is {soooo} bad (#{x}).".format(sooo="soooo", x=2)
276 % ("formatted", "string"): (
277 "This is a really really really long string that has to go inside of a"
278 " dictionary. It is %s bad (#%d)."
286 "Long keyword strings also need to be wrapped, but they will probably need to"
287 " be handled a little bit differently."
292 "But what should happen when code has already been formatted but in the wrong way?"
293 " Like with a space at the end instead of the beginning. Or what about when it is"
298 "But what should happen when code has already "
299 "been formatted but in the wrong way? Like "
300 "with a space at the end instead of the "
301 "beginning. Or what about when it is split too "
302 "soon? In the case of a split that is too "
303 "short, black will try to honer the custom "
308 "What if we have inline comments on " # First Comment
309 "each line of a bad split? In that " # Second Comment
310 "case, we should just leave it alone." # Third Comment
314 "But what should happen when code has already "
315 "been formatted but in the wrong way? Like "
316 "with a space at the end instead of the "
317 "beginning. Or what about when it is split too "
318 "soon? In the case of a split that is too "
319 "short, black will try to honer the custom "
331 "But what should happen when code has already been formatted but in the wrong"
332 " way? Like with a space at the end instead of the beginning. Or what about"
333 " when it is split too soon?"
339 "But what should happen when code has already "
340 r"been formatted but in the wrong way? Like "
341 "with a space at the end instead of the "
342 r"beginning. Or what about when it is split too "
343 r"soon? In the case of a split that is too "
344 "short, black will try to honer the custom "
353 r"This is a long raw string. When re-formatting this string, black needs to make"
354 r" sure it prepends the 'r' onto the new string."
358 "We also need to be sure to preserve any and all {} which may or may not be"
359 " attached to the string in question.".format("method calls")
362 fmt_string2 = "But what about when the string is {} but {}".format(
364 "the method call is really really really really really really really really long?",
368 "While we are on the topic of %s, we should also note that old-style formatting"
369 " must also be preserved, since some %s still uses it."
370 % ("formatting", "code")
373 old_fmt_string2 = "This is a %s %s %s %s" % (
374 "really really really really really",
376 "way to format strings!",
377 "Use f-strings instead!",
381 "Whereas only the strings after the percent sign were long in the last example,"
382 " this example uses a long initial string as well. This is another %s %s %s %s"
384 "really really really really really",
386 "way to format strings!",
387 "Use f-strings instead!",
392 f"f-strings definitely make things more {difficult} than they need to be for"
393 " {black}. But boy they sure are handy. The problem is that some lines will need"
394 f" to have the 'f' whereas others do not. This {line}, for example, needs one."
397 fstring_with_no_fexprs = (
398 f"Some regular string that needs to get split certainly but is NOT an fstring by"
399 f" any means whatsoever."
402 comment_string = ( # This comment gets thrown to the top.
403 "Long lines with inline comments should have their comments appended to the"
404 " reformatted string's enclosing right parentheses."
407 arg_comment_string = print(
408 "Long lines with inline comments which are apart of (and not the only member of) an"
409 " argument list should have their comments appended to the reformatted string's"
410 " enclosing left parentheses.", # This comment stays on the bottom.
417 pragma_comment_string1 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa: E501
419 pragma_comment_string2 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa
421 """This is a really really really long triple quote string and it should not be touched."""
423 triple_quote_string = """This is a really really really long triple quote string assignment and it should not be touched."""
425 assert some_type_of_boolean_expression, (
426 "Followed by a really really really long string that is used to provide context to"
427 " the AssertionError exception."
430 assert some_type_of_boolean_expression, (
431 "Followed by a really really really long string that is used to provide context to"
432 " the AssertionError exception, which uses dynamic string {}.".format("formatting")
435 assert some_type_of_boolean_expression, (
436 "Followed by a really really really long string that is used to provide context to"
437 " the AssertionError exception, which uses dynamic string %s."
441 assert some_type_of_boolean_expression, (
442 "Followed by a really really really long string that is used to provide context to"
443 " the AssertionError exception, which uses dynamic %s %s."
444 % ("string", "formatting")
448 "With a reallly generic name and with a really really long string that is, at some"
449 " point down the line, "
451 + " to a variable and then added to another string."
455 "With a reallly generic name and with a really really long string that is, at some"
456 " point down the line, "
458 + " to a variable and then added to another string. But then what happens when the"
459 " final string is also supppppperrrrr long?! Well then that second (realllllllly"
460 " long) string should be split too.",
461 "and a second argument",
466 "A really really really really really really really really really really really"
467 " really really long {} {}".format("return", "value")
471 "This is a really long string argument to a function that has a trailing comma"
472 " which should NOT be there.",
476 "This is a really long string argument to a function that has a trailing comma"
477 " which should NOT be there.", # comment after comma
481 "This is a really long string argument to a function that has a trailing comma"
482 " which should NOT be there.",
486 "This is a really long string argument to a function that has a trailing comma"
487 " which should NOT be there.", # comment after comma
490 func_with_bad_parens(
491 "short string that should have parens stripped", x, y, z,
494 func_with_bad_parens(
495 x, y, "short string that should have parens stripped", z,
498 annotated_variable: Final = (
503 + "using the '+' operator."
505 annotated_variable: Final = (
506 "This is a large string that has a type annotation attached to it. A type"
507 " annotation should NOT stop a long string from being wrapped."
509 annotated_variable: Literal["fakse_literal"] = (
510 "This is a large string that has a type annotation attached to it. A type"
511 " annotation should NOT stop a long string from being wrapped."
515 "This is a really long string with \"embedded\" double quotes and 'single' quotes"
516 " that also handles checking for an even number of backslashes \\"
519 "This is a really long string with \"embedded\" double quotes and 'single' quotes"
520 " that also handles checking for an even number of backslashes \\\\"
523 "This is a really 'long' string with \"embedded double quotes\" and 'single' quotes"
524 ' that also handles checking for an odd number of backslashes \\", like'
528 short_string = "Hi there."
530 func_call(short_string="Hi there.")
532 raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
537 "This is a really long string that can't possibly be expected to fit all"
538 " together on one line. In fact it may even take up three or more lines... like"
539 " four or five... but probably just three."
544 "This is a {really} long string that needs to be split without a doubt (i.e."
545 f" most definitely). In short, this {string} that can't possibly be {{expected}} to"
546 f" fit all together on one line. In {fact} it may even take up three or more"
547 " lines... like four or five... but probably just four."
550 long_unmergable_string_with_pragma = (
551 "This is a really long string that can't be merged because it has a likely pragma at the end" # type: ignore
555 long_unmergable_string_with_pragma = (
556 "This is a really long string that can't be merged because it has a likely pragma at the end" # noqa
560 long_unmergable_string_with_pragma = (
561 "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