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 inline_comments_func1(
76 "if there are inline "
77 "comments in the middle "
78 # Here is the standard alone comment.
79 "of the implicitly concatenated "
80 "string, we should handle "
85 inline_comments_func2(
86 "what if the string is very very very very very very very very very very long and this part does "
87 "not fit into a single line? "
88 # Here is the standard alone comment.
89 "then the string should still be properly handled by merging and splitting "
90 "it into parts that fit in line length.",
94 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."
96 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")
98 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?")
100 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")
102 old_fmt_string2 = "This is a %s %s %s %s" % ("really really really really really", "old", "way to format strings!", "Use f-strings instead!")
104 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!")
106 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."
108 fstring_with_no_fexprs = f"Some regular string that needs to get split certainly but is NOT an fstring by any means whatsoever."
110 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.
112 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.
113 "Arg #2", "Arg #3", "Arg #4", "Arg #5")
115 pragma_comment_string1 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa: E501
117 pragma_comment_string2 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa
119 """This is a really really really long triple quote string and it should not be touched."""
121 triple_quote_string = """This is a really really really long triple quote string assignment and it should not be touched."""
123 assert some_type_of_boolean_expression, "Followed by a really really really long string that is used to provide context to the AssertionError exception."
125 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")
127 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"
129 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")
131 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.")
133 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)
135 return "A really really really really really really really really really really really really really long {} {}".format("return", "value")
138 "This is a really long string argument to a function that has a trailing comma which should NOT be there.",
142 "This is a really long string argument to a function that has a trailing comma which should NOT be there.", # comment after comma
147 "This is a really long string argument to a function that has a trailing comma"
148 " which should NOT be there."
154 "This is a really long string argument to a function that has a trailing comma"
155 " which should NOT be there."
156 ), # comment after comma
159 func_with_bad_parens_that_wont_fit_in_one_line(
160 ("short string that should have parens stripped"),
166 func_with_bad_parens_that_wont_fit_in_one_line(
169 ("short string that should have parens stripped"),
173 func_with_bad_parens(
174 ("short string that should have parens stripped"),
180 func_with_bad_parens(
183 ("short string that should have parens stripped"),
187 annotated_variable: Final = "This is a large " + STRING + " that has been " + CONCATENATED + "using the '+' operator."
188 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."
189 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."
191 backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\"
192 backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\\\"
193 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...\\\\\\"
207 raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
210 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."
212 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."
214 long_unmergable_string_with_pragma = (
215 "This is a really long string that can't be merged because it has a likely pragma at the end" # type: ignore
219 long_unmergable_string_with_pragma = (
220 "This is a really long string that can't be merged because it has a likely pragma at the end" # noqa
224 long_unmergable_string_with_pragma = (
225 "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
229 string_with_nameescape = (
230 "........................................................................ \N{LAO KO LA}"
233 string_with_nameescape = (
234 "........................................................................... \N{LAO KO LA}"
237 string_with_nameescape = (
238 "............................................................................ \N{LAO KO LA}"
241 string_with_nameescape_and_escaped_backslash = (
242 "...................................................................... \\\N{LAO KO LA}"
245 string_with_nameescape_and_escaped_backslash = (
246 "......................................................................... \\\N{LAO KO LA}"
249 string_with_nameescape_and_escaped_backslash = (
250 ".......................................................................... \\\N{LAO KO LA}"
253 string_with_escaped_nameescape = (
254 "........................................................................ \\N{LAO KO LA}"
257 string_with_escaped_nameescape = (
258 "........................................................................... \\N{LAO KO LA}"
266 "This is a really long string that can't possibly be expected to fit all together"
267 " on one line. In fact it may even take up three or more lines... like four or"
268 " five... but probably just three."
272 "This is a really long string that can't possibly be expected to fit all together"
273 " on one line. In fact it may even take up three or more lines... like four or"
274 " five... but probably just three."
280 "This is a really long string inside of a print statement with extra arguments"
281 " attached at the end of it.",
288 "This is a really long string inside of a print statement with no extra arguments"
289 " attached at the end of it."
294 "This is a really long string that can't possibly be expected to fit all"
295 " together on one line. Also it is inside a dictionary, so formatting is more"
299 "This is another really really (not really) long string that also can't be"
300 " expected to fit on one line and is, like the other string, inside a"
307 "This is a really long string that can't possibly be expected to fit all"
308 " together on one line. Also it is inside a dictionary, so formatting is more"
312 "This is another really really (not really) long string that also can't be"
313 " expected to fit on one line and is, like the other string, inside a"
320 "This is a really long string that can't possibly be expected to fit all"
321 " together on one line. Also it is inside a dictionary, so formatting is more"
325 "This is another really really (not really) long string that also can't be"
326 " expected to fit on one line and is, like the other string, inside a"
332 "A long and ridiculous {}".format(string_key): (
333 "This is a really really really long string that has to go i,side of a"
334 " dictionary. It is soooo bad."
336 some_func("calling", "some", "stuff"): (
337 "This is a really really really long string that has to go inside of a"
338 " dictionary. It is {soooo} bad (#{x}).".format(sooo="soooo", x=2)
341 % ("formatted", "string"): (
342 "This is a really really really long string that has to go inside of a"
343 " dictionary. It is %s bad (#%d)."
351 "Long keyword strings also need to be wrapped, but they will probably need to"
352 " be handled a little bit differently."
357 "But what should happen when code has already been formatted but in the wrong way?"
358 " Like with a space at the end instead of the beginning. Or what about when it is"
363 "But what should happen when code has already "
364 "been formatted but in the wrong way? Like "
365 "with a space at the end instead of the "
366 "beginning. Or what about when it is split too "
367 "soon? In the case of a split that is too "
368 "short, black will try to honer the custom "
373 "What if we have inline comments on " # First Comment
374 "each line of a bad split? In that " # Second Comment
375 "case, we should just leave it alone." # Third Comment
379 "But what should happen when code has already "
380 "been formatted but in the wrong way? Like "
381 "with a space at the end instead of the "
382 "beginning. Or what about when it is split too "
383 "soon? In the case of a split that is too "
384 "short, black will try to honer the custom "
396 "But what should happen when code has already been formatted but in the wrong"
397 " way? Like with a space at the end instead of the beginning. Or what about"
398 " when it is split too soon?"
404 "But what should happen when code has already "
405 r"been formatted but in the wrong way? Like "
406 "with a space at the end instead of the "
407 r"beginning. Or what about when it is split too "
408 r"soon? In the case of a split that is too "
409 "short, black will try to honer the custom "
417 inline_comments_func1(
418 "if there are inline comments in the middle "
419 # Here is the standard alone comment.
420 "of the implicitly concatenated string, we should handle them correctly",
424 inline_comments_func2(
425 "what if the string is very very very very very very very very very very long and"
426 " this part does not fit into a single line? "
427 # Here is the standard alone comment.
428 "then the string should still be properly handled by merging and splitting "
429 "it into parts that fit in line length.",
434 r"This is a long raw string. When re-formatting this string, black needs to make"
435 r" sure it prepends the 'r' onto the new string."
439 "We also need to be sure to preserve any and all {} which may or may not be"
440 " attached to the string in question.".format("method calls")
443 fmt_string2 = "But what about when the string is {} but {}".format(
445 "the method call is really really really really really really really really long?",
449 "While we are on the topic of %s, we should also note that old-style formatting"
450 " must also be preserved, since some %s still uses it." % ("formatting", "code")
453 old_fmt_string2 = "This is a %s %s %s %s" % (
454 "really really really really really",
456 "way to format strings!",
457 "Use f-strings instead!",
461 "Whereas only the strings after the percent sign were long in the last example,"
462 " this example uses a long initial string as well. This is another %s %s %s %s"
464 "really really really really really",
466 "way to format strings!",
467 "Use f-strings instead!",
472 f"f-strings definitely make things more {difficult} than they need to be for"
473 " {black}. But boy they sure are handy. The problem is that some lines will need"
474 f" to have the 'f' whereas others do not. This {line}, for example, needs one."
477 fstring_with_no_fexprs = (
478 f"Some regular string that needs to get split certainly but is NOT an fstring by"
479 f" any means whatsoever."
482 comment_string = ( # This comment gets thrown to the top.
483 "Long lines with inline comments should have their comments appended to the"
484 " reformatted string's enclosing right parentheses."
487 arg_comment_string = print(
488 "Long lines with inline comments which are apart of (and not the only member of) an"
489 " argument list should have their comments appended to the reformatted string's"
490 " enclosing left parentheses.", # This comment stays on the bottom.
497 pragma_comment_string1 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa: E501
499 pragma_comment_string2 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa
501 """This is a really really really long triple quote string and it should not be touched."""
503 triple_quote_string = """This is a really really really long triple quote string assignment and it should not be touched."""
505 assert some_type_of_boolean_expression, (
506 "Followed by a really really really long string that is used to provide context to"
507 " the AssertionError exception."
510 assert some_type_of_boolean_expression, (
511 "Followed by a really really really long string that is used to provide context to"
512 " the AssertionError exception, which uses dynamic string {}.".format("formatting")
515 assert some_type_of_boolean_expression, (
516 "Followed by a really really really long string that is used to provide context to"
517 " the AssertionError exception, which uses dynamic string %s." % "formatting"
520 assert some_type_of_boolean_expression, (
521 "Followed by a really really really long string that is used to provide context to"
522 " the AssertionError exception, which uses dynamic %s %s."
523 % ("string", "formatting")
527 "With a reallly generic name and with a really really long string that is, at some"
528 " point down the line, "
530 + " to a variable and then added to another string."
534 "With a reallly generic name and with a really really long string that is, at some"
535 " point down the line, "
537 + " to a variable and then added to another string. But then what happens when the"
538 " final string is also supppppperrrrr long?! Well then that second (realllllllly"
539 " long) string should be split too.",
540 "and a second argument",
545 "A really really really really really really really really really really really"
546 " really really long {} {}".format("return", "value")
550 "This is a really long string argument to a function that has a trailing comma"
551 " which should NOT be there.",
555 "This is a really long string argument to a function that has a trailing comma"
556 " which should NOT be there.", # comment after comma
560 "This is a really long string argument to a function that has a trailing comma"
561 " which should NOT be there.",
565 "This is a really long string argument to a function that has a trailing comma"
566 " which should NOT be there.", # comment after comma
569 func_with_bad_parens_that_wont_fit_in_one_line(
570 "short string that should have parens stripped", x, y, z
573 func_with_bad_parens_that_wont_fit_in_one_line(
574 x, y, "short string that should have parens stripped", z
577 func_with_bad_parens(
578 "short string that should have parens stripped",
584 func_with_bad_parens(
587 "short string that should have parens stripped",
591 annotated_variable: Final = (
596 + "using the '+' operator."
598 annotated_variable: Final = (
599 "This is a large string that has a type annotation attached to it. A type"
600 " annotation should NOT stop a long string from being wrapped."
602 annotated_variable: Literal["fakse_literal"] = (
603 "This is a large string that has a type annotation attached to it. A type"
604 " annotation should NOT stop a long string from being wrapped."
608 "This is a really long string with \"embedded\" double quotes and 'single' quotes"
609 " that also handles checking for an even number of backslashes \\"
612 "This is a really long string with \"embedded\" double quotes and 'single' quotes"
613 " that also handles checking for an even number of backslashes \\\\"
616 "This is a really 'long' string with \"embedded double quotes\" and 'single' quotes"
617 ' that also handles checking for an odd number of backslashes \\", like'
621 short_string = "Hi there."
623 func_call(short_string="Hi there.")
625 raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
630 "This is a really long string that can't possibly be expected to fit all"
631 " together on one line. In fact it may even take up three or more lines... like"
632 " four or five... but probably just three."
637 "This is a {really} long string that needs to be split without a doubt (i.e."
638 f" most definitely). In short, this {string} that can't possibly be {{expected}} to"
639 f" fit all together on one line. In {fact} it may even take up three or more"
640 " lines... like four or five... but probably just four."
643 long_unmergable_string_with_pragma = (
644 "This is a really long string that can't be merged because it has a likely pragma at the end" # type: ignore
648 long_unmergable_string_with_pragma = (
649 "This is a really long string that can't be merged because it has a likely pragma at the end" # noqa
653 long_unmergable_string_with_pragma = (
654 "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
658 string_with_nameescape = (
659 "........................................................................"
663 string_with_nameescape = (
664 "..........................................................................."
668 string_with_nameescape = (
669 "............................................................................"
673 string_with_nameescape_and_escaped_backslash = (
674 "......................................................................"
678 string_with_nameescape_and_escaped_backslash = (
679 "........................................................................."
683 string_with_nameescape_and_escaped_backslash = (
684 ".........................................................................."
688 string_with_escaped_nameescape = (
689 "........................................................................ \\N{LAO"
693 string_with_escaped_nameescape = (
694 "..........................................................................."