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 D5 = { # Test for https://github.com/psf/black/issues/3261
22 ("This is a really long string that can't be expected to fit in one line and is used as a nested dict's key"): {"inner": "value"},
25 D6 = { # Test for https://github.com/psf/black/issues/3261
26 ("This is a really long string that can't be expected to fit in one line and is used as a dict's key"): ["value1", "value2"],
29 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")]
31 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."]
33 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")}
35 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."}
37 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"))
39 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.",)
41 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.")
44 'But what should happen when code has already been formatted but in the wrong way? Like'
45 " with a space at the end instead of the beginning. Or what about when it is split too soon?"
48 bad_split2 = "But what should happen when code has already " \
49 "been formatted but in the wrong way? Like " \
50 "with a space at the end instead of the " \
51 "beginning. Or what about when it is split too " \
52 "soon? In the case of a split that is too " \
53 "short, black will try to honer the custom " \
57 "What if we have inline comments on " # First Comment
58 "each line of a bad split? In that " # Second Comment
59 "case, we should just leave it alone." # Third Comment
63 "But what should happen when code has already "
64 "been formatted but in the wrong way? Like "
65 "with a space at the end instead of the "
66 "beginning. Or what about when it is split too "
67 "soon? In the case of a split that is too "
68 "short, black will try to honer the custom "
75 long_string_kwarg="But what should happen when code has already been formatted but in the wrong way? Like "
76 "with a space at the end instead of the beginning. Or what about when it is split too "
82 "But what should happen when code has already "
83 r"been formatted but in the wrong way? Like "
84 "with a space at the end instead of the "
85 r"beginning. Or what about when it is split too "
86 r"soon? In the case of a split that is too "
87 "short, black will try to honer the custom "
95 inline_comments_func1(
96 "if there are inline "
97 "comments in the middle "
98 # Here is the standard alone comment.
99 "of the implicitly concatenated "
100 "string, we should handle "
105 inline_comments_func2(
106 "what if the string is very very very very very very very very very very long and this part does "
107 "not fit into a single line? "
108 # Here is the standard alone comment.
109 "then the string should still be properly handled by merging and splitting "
110 "it into parts that fit in line length.",
114 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."
116 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")
118 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?")
120 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")
122 old_fmt_string2 = "This is a %s %s %s %s" % ("really really really really really", "old", "way to format strings!", "Use f-strings instead!")
124 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!")
126 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."
128 fstring_with_no_fexprs = f"Some regular string that needs to get split certainly but is NOT an fstring by any means whatsoever."
130 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.
132 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.
133 "Arg #2", "Arg #3", "Arg #4", "Arg #5")
135 pragma_comment_string1 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa: E501
137 pragma_comment_string2 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa
139 """This is a really really really long triple quote string and it should not be touched."""
141 triple_quote_string = """This is a really really really long triple quote string assignment and it should not be touched."""
143 assert some_type_of_boolean_expression, "Followed by a really really really long string that is used to provide context to the AssertionError exception."
145 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")
147 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"
149 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")
151 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.")
153 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)
155 return "A really really really really really really really really really really really really really long {} {}".format("return", "value")
158 "This is a really long string argument to a function that has a trailing comma which should NOT be there.",
162 "This is a really long string argument to a function that has a trailing comma which should NOT be there.", # comment after comma
167 "This is a really long string argument to a function that has a trailing comma"
168 " which should NOT be there."
174 "This is a really long string argument to a function that has a trailing comma"
175 " which should NOT be there."
176 ), # comment after comma
179 func_with_bad_parens_that_wont_fit_in_one_line(
180 ("short string that should have parens stripped"),
186 func_with_bad_parens_that_wont_fit_in_one_line(
189 ("short string that should have parens stripped"),
193 func_with_bad_parens(
194 ("short string that should have parens stripped"),
200 func_with_bad_parens(
203 ("short string that should have parens stripped"),
207 annotated_variable: Final = "This is a large " + STRING + " that has been " + CONCATENATED + "using the '+' operator."
208 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."
209 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."
211 backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\"
212 backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\\\"
213 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...\\\\\\"
227 raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
230 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."
232 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."
234 long_unmergable_string_with_pragma = (
235 "This is a really long string that can't be merged because it has a likely pragma at the end" # type: ignore
239 long_unmergable_string_with_pragma = (
240 "This is a really long string that can't be merged because it has a likely pragma at the end" # noqa
244 long_unmergable_string_with_pragma = (
245 "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
249 string_with_nameescape = (
250 "........................................................................ \N{LAO KO LA}"
253 string_with_nameescape = (
254 "........................................................................... \N{LAO KO LA}"
257 string_with_nameescape = (
258 "............................................................................ \N{LAO KO LA}"
261 string_with_nameescape_and_escaped_backslash = (
262 "...................................................................... \\\N{LAO KO LA}"
265 string_with_nameescape_and_escaped_backslash = (
266 "......................................................................... \\\N{LAO KO LA}"
269 string_with_nameescape_and_escaped_backslash = (
270 ".......................................................................... \\\N{LAO KO LA}"
273 string_with_escaped_nameescape = (
274 "........................................................................ \\N{LAO KO LA}"
277 string_with_escaped_nameescape = (
278 "........................................................................... \\N{LAO KO LA}"
286 "This is a really long string that can't possibly be expected to fit all together"
287 " on one line. In fact it may even take up three or more lines... like four or"
288 " five... but probably just three."
292 "This is a really long string that can't possibly be expected to fit all together"
293 " on one line. In fact it may even take up three or more lines... like four or"
294 " five... but probably just three."
300 "This is a really long string inside of a print statement with extra arguments"
301 " attached at the end of it.",
308 "This is a really long string inside of a print statement with no extra arguments"
309 " attached at the end of it."
314 "This is a really long string that can't possibly be expected to fit all"
315 " together on one line. Also it is inside a dictionary, so formatting is more"
319 "This is another really really (not really) long string that also can't be"
320 " expected to fit on one line and is, like the other string, inside a"
327 "This is a really long string that can't possibly be expected to fit all"
328 " together on one line. Also it is inside a dictionary, so formatting is more"
332 "This is another really really (not really) long string that also can't be"
333 " expected to fit on one line and is, like the other string, inside a"
340 "This is a really long string that can't possibly be expected to fit all"
341 " together on one line. Also it is inside a dictionary, so formatting is more"
345 "This is another really really (not really) long string that also can't be"
346 " expected to fit on one line and is, like the other string, inside a"
352 "A long and ridiculous {}".format(string_key): (
353 "This is a really really really long string that has to go i,side of a"
354 " dictionary. It is soooo bad."
356 some_func("calling", "some", "stuff"): (
357 "This is a really really really long string that has to go inside of a"
358 " dictionary. It is {soooo} bad (#{x}).".format(sooo="soooo", x=2)
361 % ("formatted", "string"): (
362 "This is a really really really long string that has to go inside of a"
363 " dictionary. It is %s bad (#%d)."
368 D5 = { # Test for https://github.com/psf/black/issues/3261
369 "This is a really long string that can't be expected to fit in one line and is used as a nested dict's key": {
374 D6 = { # Test for https://github.com/psf/black/issues/3261
375 "This is a really long string that can't be expected to fit in one line and is used as a dict's key": [
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 list literal, so it's expected to"
386 " be 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 list"
394 "parens should be stripped for short string in list",
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 list 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 set literal, so it's expected to be"
407 " 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 set"
415 "parens should be stripped for short string in set",
419 "This is a really long string that can't be expected to fit in one line and is the"
420 " only child of a set literal."
424 "The is a short string",
426 "This is a really long string that can't possibly be expected to fit all"
427 " together on one line. Also it is inside a tuple literal, so it's expected to"
428 " be wrapped in parens when spliting to avoid implicit str concatenation."
430 short_call("arg", {"key": "value"}),
432 "This is another really really (not really) long string that also can't be"
433 " expected to fit on one line and is, like the other string, inside a tuple"
436 "parens should be stripped for short string in list",
441 "This is a really long string that can't be expected to fit in one line and is"
442 " the only child of a tuple literal."
449 "Long keyword strings also need to be wrapped, but they will probably need to"
450 " be handled a little bit differently."
455 "But what should happen when code has already been formatted but in the wrong way?"
456 " Like with a space at the end instead of the beginning. Or what about when it is"
461 "But what should happen when code has already "
462 "been formatted but in the wrong way? Like "
463 "with a space at the end instead of the "
464 "beginning. Or what about when it is split too "
465 "soon? In the case of a split that is too "
466 "short, black will try to honer the custom "
471 "What if we have inline comments on " # First Comment
472 "each line of a bad split? In that " # Second Comment
473 "case, we should just leave it alone." # Third Comment
477 "But what should happen when code has already "
478 "been formatted but in the wrong way? Like "
479 "with a space at the end instead of the "
480 "beginning. Or what about when it is split too "
481 "soon? In the case of a split that is too "
482 "short, black will try to honer the custom "
494 "But what should happen when code has already been formatted but in the wrong"
495 " way? Like with a space at the end instead of the beginning. Or what about"
496 " when it is split too soon?"
502 "But what should happen when code has already "
503 r"been formatted but in the wrong way? Like "
504 "with a space at the end instead of the "
505 r"beginning. Or what about when it is split too "
506 r"soon? In the case of a split that is too "
507 "short, black will try to honer the custom "
515 inline_comments_func1(
516 "if there are inline comments in the middle "
517 # Here is the standard alone comment.
518 "of the implicitly concatenated string, we should handle them correctly",
522 inline_comments_func2(
523 "what if the string is very very very very very very very very very very long and"
524 " this part does not fit into a single line? "
525 # Here is the standard alone comment.
526 "then the string should still be properly handled by merging and splitting "
527 "it into parts that fit in line length.",
532 r"This is a long raw string. When re-formatting this string, black needs to make"
533 r" sure it prepends the 'r' onto the new string."
537 "We also need to be sure to preserve any and all {} which may or may not be"
538 " attached to the string in question.".format("method calls")
541 fmt_string2 = "But what about when the string is {} but {}".format(
543 "the method call is really really really really really really really really long?",
547 "While we are on the topic of %s, we should also note that old-style formatting"
548 " must also be preserved, since some %s still uses it." % ("formatting", "code")
551 old_fmt_string2 = "This is a %s %s %s %s" % (
552 "really really really really really",
554 "way to format strings!",
555 "Use f-strings instead!",
559 "Whereas only the strings after the percent sign were long in the last example,"
560 " this example uses a long initial string as well. This is another %s %s %s %s"
562 "really really really really really",
564 "way to format strings!",
565 "Use f-strings instead!",
570 f"f-strings definitely make things more {difficult} than they need to be for"
571 " {black}. But boy they sure are handy. The problem is that some lines will need"
572 f" to have the 'f' whereas others do not. This {line}, for example, needs one."
575 fstring_with_no_fexprs = (
576 f"Some regular string that needs to get split certainly but is NOT an fstring by"
577 f" any means whatsoever."
580 comment_string = ( # This comment gets thrown to the top.
581 "Long lines with inline comments should have their comments appended to the"
582 " reformatted string's enclosing right parentheses."
585 arg_comment_string = print(
586 "Long lines with inline comments which are apart of (and not the only member of) an"
587 " argument list should have their comments appended to the reformatted string's"
588 " enclosing left parentheses.", # This comment gets thrown to the top.
595 pragma_comment_string1 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa: E501
597 pragma_comment_string2 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa
599 """This is a really really really long triple quote string and it should not be touched."""
601 triple_quote_string = """This is a really really really long triple quote string assignment and it should not be touched."""
603 assert some_type_of_boolean_expression, (
604 "Followed by a really really really long string that is used to provide context to"
605 " the AssertionError exception."
608 assert some_type_of_boolean_expression, (
609 "Followed by a really really really long string that is used to provide context to"
610 " the AssertionError exception, which uses dynamic string {}.".format("formatting")
613 assert some_type_of_boolean_expression, (
614 "Followed by a really really really long string that is used to provide context to"
615 " the AssertionError exception, which uses dynamic string %s." % "formatting"
618 assert some_type_of_boolean_expression, (
619 "Followed by a really really really long string that is used to provide context to"
620 " the AssertionError exception, which uses dynamic %s %s."
621 % ("string", "formatting")
625 "With a reallly generic name and with a really really long string that is, at some"
626 " point down the line, "
628 + " to a variable and then added to another string."
632 "With a reallly generic name and with a really really long string that is, at some"
633 " point down the line, "
635 + " to a variable and then added to another string. But then what happens when the"
636 " final string is also supppppperrrrr long?! Well then that second (realllllllly"
637 " long) string should be split too.",
638 "and a second argument",
643 "A really really really really really really really really really really really"
644 " really really long {} {}".format("return", "value")
648 "This is a really long string argument to a function that has a trailing comma"
649 " which should NOT be there.",
653 "This is a really long string argument to a function that has a trailing comma"
654 " which should NOT be there.", # comment after comma
658 "This is a really long string argument to a function that has a trailing comma"
659 " which should NOT be there.",
663 "This is a really long string argument to a function that has a trailing comma"
664 " which should NOT be there.", # comment after comma
667 func_with_bad_parens_that_wont_fit_in_one_line(
668 "short string that should have parens stripped", x, y, z
671 func_with_bad_parens_that_wont_fit_in_one_line(
672 x, y, "short string that should have parens stripped", z
675 func_with_bad_parens(
676 "short string that should have parens stripped",
682 func_with_bad_parens(
685 "short string that should have parens stripped",
689 annotated_variable: Final = (
694 + "using the '+' operator."
696 annotated_variable: Final = (
697 "This is a large string that has a type annotation attached to it. A type"
698 " annotation should NOT stop a long string from being wrapped."
700 annotated_variable: Literal["fakse_literal"] = (
701 "This is a large string that has a type annotation attached to it. A type"
702 " annotation should NOT stop a long string from being wrapped."
706 "This is a really long string with \"embedded\" double quotes and 'single' quotes"
707 " that also handles checking for an even number of backslashes \\"
710 "This is a really long string with \"embedded\" double quotes and 'single' quotes"
711 " that also handles checking for an even number of backslashes \\\\"
714 "This is a really 'long' string with \"embedded double quotes\" and 'single' quotes"
715 ' that also handles checking for an odd number of backslashes \\", like'
719 short_string = "Hi there."
721 func_call(short_string="Hi there.")
723 raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
728 "This is a really long string that can't possibly be expected to fit all"
729 " together on one line. In fact it may even take up three or more lines... like"
730 " four or five... but probably just three."
735 "This is a {really} long string that needs to be split without a doubt (i.e."
736 f" most definitely). In short, this {string} that can't possibly be {{expected}} to"
737 f" fit all together on one line. In {fact} it may even take up three or more"
738 " lines... like four or five... but probably just four."
741 long_unmergable_string_with_pragma = (
742 "This is a really long string that can't be merged because it has a likely pragma at the end" # type: ignore
746 long_unmergable_string_with_pragma = (
747 "This is a really long string that can't be merged because it has a likely pragma at the end" # noqa
751 long_unmergable_string_with_pragma = (
752 "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
756 string_with_nameescape = (
757 "........................................................................"
761 string_with_nameescape = (
762 "..........................................................................."
766 string_with_nameescape = (
767 "............................................................................"
771 string_with_nameescape_and_escaped_backslash = (
772 "......................................................................"
776 string_with_nameescape_and_escaped_backslash = (
777 "........................................................................."
781 string_with_nameescape_and_escaped_backslash = (
782 ".........................................................................."
786 string_with_escaped_nameescape = (
787 "........................................................................ \\N{LAO"
791 string_with_escaped_nameescape = (
792 "..........................................................................."