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 L1 = ["The is a short string", "This is a really long string that can't possibly be expected to fit all together on one line. Also it is inside a list literal, so it's expected to be wrapped in parens when spliting to avoid implicit str concatenation.", short_call("arg", {"key": "value"}), "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 list literal.", ("parens should be stripped for short string in list")]
23 L2 = ["This is a really long string that can't be expected to fit in one line and is the only child of a list literal."]
25 S1 = {"The is a short string", "This is a really long string that can't possibly be expected to fit all together on one line. Also it is inside a set literal, so it's expected to be wrapped in parens when spliting to avoid implicit str concatenation.", short_call("arg", {"key": "value"}), "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 set literal.", ("parens should be stripped for short string in set")}
27 S2 = {"This is a really long string that can't be expected to fit in one line and is the only child of a set literal."}
29 T1 = ("The is a short string", "This is a really long string that can't possibly be expected to fit all together on one line. Also it is inside a tuple literal, so it's expected to be wrapped in parens when spliting to avoid implicit str concatenation.", short_call("arg", {"key": "value"}), "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 tuple literal.", ("parens should be stripped for short string in list"))
31 T2 = ("This is a really long string that can't be expected to fit in one line and is the only child of a tuple literal.",)
33 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.")
36 'But what should happen when code has already been formatted but in the wrong way? Like'
37 " with a space at the end instead of the beginning. Or what about when it is split too soon?"
40 bad_split2 = "But what should happen when code has already " \
41 "been formatted but in the wrong way? Like " \
42 "with a space at the end instead of the " \
43 "beginning. Or what about when it is split too " \
44 "soon? In the case of a split that is too " \
45 "short, black will try to honer the custom " \
49 "What if we have inline comments on " # First Comment
50 "each line of a bad split? In that " # Second Comment
51 "case, we should just leave it alone." # Third Comment
55 "But what should happen when code has already "
56 "been formatted but in the wrong way? Like "
57 "with a space at the end instead of the "
58 "beginning. Or what about when it is split too "
59 "soon? In the case of a split that is too "
60 "short, black will try to honer the custom "
67 long_string_kwarg="But what should happen when code has already been formatted but in the wrong way? Like "
68 "with a space at the end instead of the beginning. Or what about when it is split too "
74 "But what should happen when code has already "
75 r"been formatted but in the wrong way? Like "
76 "with a space at the end instead of the "
77 r"beginning. Or what about when it is split too "
78 r"soon? In the case of a split that is too "
79 "short, black will try to honer the custom "
87 inline_comments_func1(
88 "if there are inline "
89 "comments in the middle "
90 # Here is the standard alone comment.
91 "of the implicitly concatenated "
92 "string, we should handle "
97 inline_comments_func2(
98 "what if the string is very very very very very very very very very very long and this part does "
99 "not fit into a single line? "
100 # Here is the standard alone comment.
101 "then the string should still be properly handled by merging and splitting "
102 "it into parts that fit in line length.",
106 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."
108 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")
110 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?")
112 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")
114 old_fmt_string2 = "This is a %s %s %s %s" % ("really really really really really", "old", "way to format strings!", "Use f-strings instead!")
116 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!")
118 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."
120 fstring_with_no_fexprs = f"Some regular string that needs to get split certainly but is NOT an fstring by any means whatsoever."
122 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.
124 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 gets thrown to the top.
125 "Arg #2", "Arg #3", "Arg #4", "Arg #5")
127 pragma_comment_string1 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa: E501
129 pragma_comment_string2 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa
131 """This is a really really really long triple quote string and it should not be touched."""
133 triple_quote_string = """This is a really really really long triple quote string assignment and it should not be touched."""
135 assert some_type_of_boolean_expression, "Followed by a really really really long string that is used to provide context to the AssertionError exception."
137 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")
139 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"
141 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")
143 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.")
145 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)
147 return "A really really really really really really really really really really really really really long {} {}".format("return", "value")
150 "This is a really long string argument to a function that has a trailing comma which should NOT be there.",
154 "This is a really long string argument to a function that has a trailing comma which should NOT be there.", # comment after comma
159 "This is a really long string argument to a function that has a trailing comma"
160 " which should NOT be there."
166 "This is a really long string argument to a function that has a trailing comma"
167 " which should NOT be there."
168 ), # comment after comma
171 func_with_bad_parens_that_wont_fit_in_one_line(
172 ("short string that should have parens stripped"),
178 func_with_bad_parens_that_wont_fit_in_one_line(
181 ("short string that should have parens stripped"),
185 func_with_bad_parens(
186 ("short string that should have parens stripped"),
192 func_with_bad_parens(
195 ("short string that should have parens stripped"),
199 annotated_variable: Final = "This is a large " + STRING + " that has been " + CONCATENATED + "using the '+' operator."
200 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."
201 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."
203 backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\"
204 backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\\\"
205 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...\\\\\\"
219 raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
222 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."
224 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."
226 long_unmergable_string_with_pragma = (
227 "This is a really long string that can't be merged because it has a likely pragma at the end" # type: ignore
231 long_unmergable_string_with_pragma = (
232 "This is a really long string that can't be merged because it has a likely pragma at the end" # noqa
236 long_unmergable_string_with_pragma = (
237 "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
241 string_with_nameescape = (
242 "........................................................................ \N{LAO KO LA}"
245 string_with_nameescape = (
246 "........................................................................... \N{LAO KO LA}"
249 string_with_nameescape = (
250 "............................................................................ \N{LAO KO LA}"
253 string_with_nameescape_and_escaped_backslash = (
254 "...................................................................... \\\N{LAO KO LA}"
257 string_with_nameescape_and_escaped_backslash = (
258 "......................................................................... \\\N{LAO KO LA}"
261 string_with_nameescape_and_escaped_backslash = (
262 ".......................................................................... \\\N{LAO KO LA}"
265 string_with_escaped_nameescape = (
266 "........................................................................ \\N{LAO KO LA}"
269 string_with_escaped_nameescape = (
270 "........................................................................... \\N{LAO KO LA}"
278 "This is a really long string that can't possibly be expected to fit all together"
279 " on one line. In fact it may even take up three or more lines... like four or"
280 " five... but probably just three."
284 "This is a really long string that can't possibly be expected to fit all together"
285 " on one line. In fact it may even take up three or more lines... like four or"
286 " five... but probably just three."
292 "This is a really long string inside of a print statement with extra arguments"
293 " attached at the end of it.",
300 "This is a really long string inside of a print statement with no extra arguments"
301 " attached at the end of it."
306 "This is a really long string that can't possibly be expected to fit all"
307 " together on one line. Also it is inside a dictionary, so formatting is more"
311 "This is another really really (not really) long string that also can't be"
312 " expected to fit on one line and is, like the other string, inside a"
319 "This is a really long string that can't possibly be expected to fit all"
320 " together on one line. Also it is inside a dictionary, so formatting is more"
324 "This is another really really (not really) long string that also can't be"
325 " expected to fit on one line and is, like the other string, inside a"
332 "This is a really long string that can't possibly be expected to fit all"
333 " together on one line. Also it is inside a dictionary, so formatting is more"
337 "This is another really really (not really) long string that also can't be"
338 " expected to fit on one line and is, like the other string, inside a"
344 "A long and ridiculous {}".format(string_key): (
345 "This is a really really really long string that has to go i,side of a"
346 " dictionary. It is soooo bad."
348 some_func("calling", "some", "stuff"): (
349 "This is a really really really long string that has to go inside of a"
350 " dictionary. It is {soooo} bad (#{x}).".format(sooo="soooo", x=2)
353 % ("formatted", "string"): (
354 "This is a really really really long string that has to go inside of a"
355 " dictionary. It is %s bad (#%d)."
361 "The is a short string",
363 "This is a really long string that can't possibly be expected to fit all"
364 " together on one line. Also it is inside a list literal, so it's expected to"
365 " be wrapped in parens when spliting to avoid implicit str concatenation."
367 short_call("arg", {"key": "value"}),
369 "This is another really really (not really) long string that also can't be"
370 " expected to fit on one line and is, like the other string, inside a list"
373 "parens should be stripped for short string in list",
377 "This is a really long string that can't be expected to fit in one line and is the"
378 " only child of a list literal."
382 "The is a short string",
384 "This is a really long string that can't possibly be expected to fit all"
385 " together on one line. Also it is inside a set literal, so it's expected to be"
386 " wrapped in parens when spliting to avoid implicit str concatenation."
388 short_call("arg", {"key": "value"}),
390 "This is another really really (not really) long string that also can't be"
391 " expected to fit on one line and is, like the other string, inside a set"
394 "parens should be stripped for short string in set",
398 "This is a really long string that can't be expected to fit in one line and is the"
399 " only child of a set literal."
403 "The is a short string",
405 "This is a really long string that can't possibly be expected to fit all"
406 " together on one line. Also it is inside a tuple literal, so it's expected to"
407 " be wrapped in parens when spliting to avoid implicit str concatenation."
409 short_call("arg", {"key": "value"}),
411 "This is another really really (not really) long string that also can't be"
412 " expected to fit on one line and is, like the other string, inside a tuple"
415 "parens should be stripped for short string in list",
420 "This is a really long string that can't be expected to fit in one line and is"
421 " the only child of a tuple literal."
428 "Long keyword strings also need to be wrapped, but they will probably need to"
429 " be handled a little bit differently."
434 "But what should happen when code has already been formatted but in the wrong way?"
435 " Like with a space at the end instead of the beginning. Or what about when it is"
440 "But what should happen when code has already "
441 "been formatted but in the wrong way? Like "
442 "with a space at the end instead of the "
443 "beginning. Or what about when it is split too "
444 "soon? In the case of a split that is too "
445 "short, black will try to honer the custom "
450 "What if we have inline comments on " # First Comment
451 "each line of a bad split? In that " # Second Comment
452 "case, we should just leave it alone." # Third Comment
456 "But what should happen when code has already "
457 "been formatted but in the wrong way? Like "
458 "with a space at the end instead of the "
459 "beginning. Or what about when it is split too "
460 "soon? In the case of a split that is too "
461 "short, black will try to honer the custom "
473 "But what should happen when code has already been formatted but in the wrong"
474 " way? Like with a space at the end instead of the beginning. Or what about"
475 " when it is split too soon?"
481 "But what should happen when code has already "
482 r"been formatted but in the wrong way? Like "
483 "with a space at the end instead of the "
484 r"beginning. Or what about when it is split too "
485 r"soon? In the case of a split that is too "
486 "short, black will try to honer the custom "
494 inline_comments_func1(
495 "if there are inline comments in the middle "
496 # Here is the standard alone comment.
497 "of the implicitly concatenated string, we should handle them correctly",
501 inline_comments_func2(
502 "what if the string is very very very very very very very very very very long and"
503 " this part does not fit into a single line? "
504 # Here is the standard alone comment.
505 "then the string should still be properly handled by merging and splitting "
506 "it into parts that fit in line length.",
511 r"This is a long raw string. When re-formatting this string, black needs to make"
512 r" sure it prepends the 'r' onto the new string."
516 "We also need to be sure to preserve any and all {} which may or may not be"
517 " attached to the string in question.".format("method calls")
520 fmt_string2 = "But what about when the string is {} but {}".format(
522 "the method call is really really really really really really really really long?",
526 "While we are on the topic of %s, we should also note that old-style formatting"
527 " must also be preserved, since some %s still uses it." % ("formatting", "code")
530 old_fmt_string2 = "This is a %s %s %s %s" % (
531 "really really really really really",
533 "way to format strings!",
534 "Use f-strings instead!",
538 "Whereas only the strings after the percent sign were long in the last example,"
539 " this example uses a long initial string as well. This is another %s %s %s %s"
541 "really really really really really",
543 "way to format strings!",
544 "Use f-strings instead!",
549 f"f-strings definitely make things more {difficult} than they need to be for"
550 " {black}. But boy they sure are handy. The problem is that some lines will need"
551 f" to have the 'f' whereas others do not. This {line}, for example, needs one."
554 fstring_with_no_fexprs = (
555 f"Some regular string that needs to get split certainly but is NOT an fstring by"
556 f" any means whatsoever."
559 comment_string = ( # This comment gets thrown to the top.
560 "Long lines with inline comments should have their comments appended to the"
561 " reformatted string's enclosing right parentheses."
564 arg_comment_string = print(
565 "Long lines with inline comments which are apart of (and not the only member of) an"
566 " argument list should have their comments appended to the reformatted string's"
567 " enclosing left parentheses.", # This comment gets thrown to the top.
574 pragma_comment_string1 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa: E501
576 pragma_comment_string2 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa
578 """This is a really really really long triple quote string and it should not be touched."""
580 triple_quote_string = """This is a really really really long triple quote string assignment and it should not be touched."""
582 assert some_type_of_boolean_expression, (
583 "Followed by a really really really long string that is used to provide context to"
584 " the AssertionError exception."
587 assert some_type_of_boolean_expression, (
588 "Followed by a really really really long string that is used to provide context to"
589 " the AssertionError exception, which uses dynamic string {}.".format("formatting")
592 assert some_type_of_boolean_expression, (
593 "Followed by a really really really long string that is used to provide context to"
594 " the AssertionError exception, which uses dynamic string %s." % "formatting"
597 assert some_type_of_boolean_expression, (
598 "Followed by a really really really long string that is used to provide context to"
599 " the AssertionError exception, which uses dynamic %s %s."
600 % ("string", "formatting")
604 "With a reallly generic name and with a really really long string that is, at some"
605 " point down the line, "
607 + " to a variable and then added to another string."
611 "With a reallly generic name and with a really really long string that is, at some"
612 " point down the line, "
614 + " to a variable and then added to another string. But then what happens when the"
615 " final string is also supppppperrrrr long?! Well then that second (realllllllly"
616 " long) string should be split too.",
617 "and a second argument",
622 "A really really really really really really really really really really really"
623 " really really long {} {}".format("return", "value")
627 "This is a really long string argument to a function that has a trailing comma"
628 " which should NOT be there.",
632 "This is a really long string argument to a function that has a trailing comma"
633 " which should NOT be there.", # comment after comma
637 "This is a really long string argument to a function that has a trailing comma"
638 " which should NOT be there.",
642 "This is a really long string argument to a function that has a trailing comma"
643 " which should NOT be there.", # comment after comma
646 func_with_bad_parens_that_wont_fit_in_one_line(
647 "short string that should have parens stripped", x, y, z
650 func_with_bad_parens_that_wont_fit_in_one_line(
651 x, y, "short string that should have parens stripped", z
654 func_with_bad_parens(
655 "short string that should have parens stripped",
661 func_with_bad_parens(
664 "short string that should have parens stripped",
668 annotated_variable: Final = (
673 + "using the '+' operator."
675 annotated_variable: Final = (
676 "This is a large string that has a type annotation attached to it. A type"
677 " annotation should NOT stop a long string from being wrapped."
679 annotated_variable: Literal["fakse_literal"] = (
680 "This is a large string that has a type annotation attached to it. A type"
681 " annotation should NOT stop a long string from being wrapped."
685 "This is a really long string with \"embedded\" double quotes and 'single' quotes"
686 " that also handles checking for an even number of backslashes \\"
689 "This is a really long string with \"embedded\" double quotes and 'single' quotes"
690 " that also handles checking for an even number of backslashes \\\\"
693 "This is a really 'long' string with \"embedded double quotes\" and 'single' quotes"
694 ' that also handles checking for an odd number of backslashes \\", like'
698 short_string = "Hi there."
700 func_call(short_string="Hi there.")
702 raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
707 "This is a really long string that can't possibly be expected to fit all"
708 " together on one line. In fact it may even take up three or more lines... like"
709 " four or five... but probably just three."
714 "This is a {really} long string that needs to be split without a doubt (i.e."
715 f" most definitely). In short, this {string} that can't possibly be {{expected}} to"
716 f" fit all together on one line. In {fact} it may even take up three or more"
717 " lines... like four or five... but probably just four."
720 long_unmergable_string_with_pragma = (
721 "This is a really long string that can't be merged because it has a likely pragma at the end" # type: ignore
725 long_unmergable_string_with_pragma = (
726 "This is a really long string that can't be merged because it has a likely pragma at the end" # noqa
730 long_unmergable_string_with_pragma = (
731 "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
735 string_with_nameescape = (
736 "........................................................................"
740 string_with_nameescape = (
741 "..........................................................................."
745 string_with_nameescape = (
746 "............................................................................"
750 string_with_nameescape_and_escaped_backslash = (
751 "......................................................................"
755 string_with_nameescape_and_escaped_backslash = (
756 "........................................................................."
760 string_with_nameescape_and_escaped_backslash = (
761 ".........................................................................."
765 string_with_escaped_nameescape = (
766 "........................................................................ \\N{LAO"
770 string_with_escaped_nameescape = (
771 "..........................................................................."