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_that_wont_fit_in_one_line(
141 ("short string that should have parens stripped"),
147 func_with_bad_parens_that_wont_fit_in_one_line(
150 ("short string that should have parens stripped"),
154 func_with_bad_parens(
155 ("short string that should have parens stripped"),
161 func_with_bad_parens(
164 ("short string that should have parens stripped"),
168 annotated_variable: Final = "This is a large " + STRING + " that has been " + CONCATENATED + "using the '+' operator."
169 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."
170 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."
172 backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\"
173 backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\\\"
174 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...\\\\\\"
188 raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
191 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."
193 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."
195 long_unmergable_string_with_pragma = (
196 "This is a really long string that can't be merged because it has a likely pragma at the end" # type: ignore
200 long_unmergable_string_with_pragma = (
201 "This is a really long string that can't be merged because it has a likely pragma at the end" # noqa
205 long_unmergable_string_with_pragma = (
206 "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
210 string_with_nameescape = (
211 "........................................................................ \N{LAO KO LA}"
214 string_with_nameescape = (
215 "........................................................................... \N{LAO KO LA}"
218 string_with_nameescape = (
219 "............................................................................ \N{LAO KO LA}"
222 string_with_nameescape_and_escaped_backslash = (
223 "...................................................................... \\\N{LAO KO LA}"
226 string_with_nameescape_and_escaped_backslash = (
227 "......................................................................... \\\N{LAO KO LA}"
230 string_with_nameescape_and_escaped_backslash = (
231 ".......................................................................... \\\N{LAO KO LA}"
234 string_with_escaped_nameescape = (
235 "........................................................................ \\N{LAO KO LA}"
238 string_with_escaped_nameescape = (
239 "........................................................................... \\N{LAO KO LA}"
247 "This is a really long string that can't possibly be expected to fit all together"
248 " on one line. In fact it may even take up three or more lines... like four or"
249 " five... but probably just three."
253 "This is a really long string that can't possibly be expected to fit all together"
254 " on one line. In fact it may even take up three or more lines... like four or"
255 " five... but probably just three."
261 "This is a really long string inside of a print statement with extra arguments"
262 " attached at the end of it.",
269 "This is a really long string inside of a print statement with no extra arguments"
270 " attached at the end of it."
275 "This is a really long string that can't possibly be expected to fit all"
276 " together on one line. Also it is inside a dictionary, so formatting is more"
280 "This is another really really (not really) long string that also can't be"
281 " expected to fit on one line and is, like the other string, inside a"
288 "This is a really long string that can't possibly be expected to fit all"
289 " together on one line. Also it is inside a dictionary, so formatting is more"
293 "This is another really really (not really) long string that also can't be"
294 " expected to fit on one line and is, like the other string, inside a"
301 "This is a really long string that can't possibly be expected to fit all"
302 " together on one line. Also it is inside a dictionary, so formatting is more"
306 "This is another really really (not really) long string that also can't be"
307 " expected to fit on one line and is, like the other string, inside a"
313 "A long and ridiculous {}".format(string_key): (
314 "This is a really really really long string that has to go i,side of a"
315 " dictionary. It is soooo bad."
317 some_func("calling", "some", "stuff"): (
318 "This is a really really really long string that has to go inside of a"
319 " dictionary. It is {soooo} bad (#{x}).".format(sooo="soooo", x=2)
322 % ("formatted", "string"): (
323 "This is a really really really long string that has to go inside of a"
324 " dictionary. It is %s bad (#%d)."
332 "Long keyword strings also need to be wrapped, but they will probably need to"
333 " be handled a little bit differently."
338 "But what should happen when code has already been formatted but in the wrong way?"
339 " Like with a space at the end instead of the beginning. Or what about when it is"
344 "But what should happen when code has already "
345 "been formatted but in the wrong way? Like "
346 "with a space at the end instead of the "
347 "beginning. Or what about when it is split too "
348 "soon? In the case of a split that is too "
349 "short, black will try to honer the custom "
354 "What if we have inline comments on " # First Comment
355 "each line of a bad split? In that " # Second Comment
356 "case, we should just leave it alone." # Third Comment
360 "But what should happen when code has already "
361 "been formatted but in the wrong way? Like "
362 "with a space at the end instead of the "
363 "beginning. Or what about when it is split too "
364 "soon? In the case of a split that is too "
365 "short, black will try to honer the custom "
377 "But what should happen when code has already been formatted but in the wrong"
378 " way? Like with a space at the end instead of the beginning. Or what about"
379 " when it is split too soon?"
385 "But what should happen when code has already "
386 r"been formatted but in the wrong way? Like "
387 "with a space at the end instead of the "
388 r"beginning. Or what about when it is split too "
389 r"soon? In the case of a split that is too "
390 "short, black will try to honer the custom "
399 r"This is a long raw string. When re-formatting this string, black needs to make"
400 r" sure it prepends the 'r' onto the new string."
404 "We also need to be sure to preserve any and all {} which may or may not be"
405 " attached to the string in question.".format("method calls")
408 fmt_string2 = "But what about when the string is {} but {}".format(
410 "the method call is really really really really really really really really long?",
414 "While we are on the topic of %s, we should also note that old-style formatting"
415 " must also be preserved, since some %s still uses it." % ("formatting", "code")
418 old_fmt_string2 = "This is a %s %s %s %s" % (
419 "really really really really really",
421 "way to format strings!",
422 "Use f-strings instead!",
426 "Whereas only the strings after the percent sign were long in the last example,"
427 " this example uses a long initial string as well. This is another %s %s %s %s"
429 "really really really really really",
431 "way to format strings!",
432 "Use f-strings instead!",
437 f"f-strings definitely make things more {difficult} than they need to be for"
438 " {black}. But boy they sure are handy. The problem is that some lines will need"
439 f" to have the 'f' whereas others do not. This {line}, for example, needs one."
442 fstring_with_no_fexprs = (
443 f"Some regular string that needs to get split certainly but is NOT an fstring by"
444 f" any means whatsoever."
447 comment_string = ( # This comment gets thrown to the top.
448 "Long lines with inline comments should have their comments appended to the"
449 " reformatted string's enclosing right parentheses."
452 arg_comment_string = print(
453 "Long lines with inline comments which are apart of (and not the only member of) an"
454 " argument list should have their comments appended to the reformatted string's"
455 " enclosing left parentheses.", # This comment stays on the bottom.
462 pragma_comment_string1 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa: E501
464 pragma_comment_string2 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa
466 """This is a really really really long triple quote string and it should not be touched."""
468 triple_quote_string = """This is a really really really long triple quote string assignment and it should not be touched."""
470 assert some_type_of_boolean_expression, (
471 "Followed by a really really really long string that is used to provide context to"
472 " the AssertionError exception."
475 assert some_type_of_boolean_expression, (
476 "Followed by a really really really long string that is used to provide context to"
477 " the AssertionError exception, which uses dynamic string {}.".format("formatting")
480 assert some_type_of_boolean_expression, (
481 "Followed by a really really really long string that is used to provide context to"
482 " the AssertionError exception, which uses dynamic string %s." % "formatting"
485 assert some_type_of_boolean_expression, (
486 "Followed by a really really really long string that is used to provide context to"
487 " the AssertionError exception, which uses dynamic %s %s."
488 % ("string", "formatting")
492 "With a reallly generic name and with a really really long string that is, at some"
493 " point down the line, "
495 + " to a variable and then added to another string."
499 "With a reallly generic name and with a really really long string that is, at some"
500 " point down the line, "
502 + " to a variable and then added to another string. But then what happens when the"
503 " final string is also supppppperrrrr long?! Well then that second (realllllllly"
504 " long) string should be split too.",
505 "and a second argument",
510 "A really really really really really really really really really really really"
511 " really really long {} {}".format("return", "value")
515 "This is a really long string argument to a function that has a trailing comma"
516 " which should NOT be there.",
520 "This is a really long string argument to a function that has a trailing comma"
521 " which should NOT be there.", # comment after comma
525 "This is a really long string argument to a function that has a trailing comma"
526 " which should NOT be there.",
530 "This is a really long string argument to a function that has a trailing comma"
531 " which should NOT be there.", # comment after comma
534 func_with_bad_parens_that_wont_fit_in_one_line(
535 "short string that should have parens stripped", x, y, z
538 func_with_bad_parens_that_wont_fit_in_one_line(
539 x, y, "short string that should have parens stripped", z
542 func_with_bad_parens(
543 "short string that should have parens stripped",
549 func_with_bad_parens(
552 "short string that should have parens stripped",
556 annotated_variable: Final = (
561 + "using the '+' operator."
563 annotated_variable: Final = (
564 "This is a large string that has a type annotation attached to it. A type"
565 " annotation should NOT stop a long string from being wrapped."
567 annotated_variable: Literal["fakse_literal"] = (
568 "This is a large string that has a type annotation attached to it. A type"
569 " annotation should NOT stop a long string from being wrapped."
573 "This is a really long string with \"embedded\" double quotes and 'single' quotes"
574 " that also handles checking for an even number of backslashes \\"
577 "This is a really long string with \"embedded\" double quotes and 'single' quotes"
578 " that also handles checking for an even number of backslashes \\\\"
581 "This is a really 'long' string with \"embedded double quotes\" and 'single' quotes"
582 ' that also handles checking for an odd number of backslashes \\", like'
586 short_string = "Hi there."
588 func_call(short_string="Hi there.")
590 raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
595 "This is a really long string that can't possibly be expected to fit all"
596 " together on one line. In fact it may even take up three or more lines... like"
597 " four or five... but probably just three."
602 "This is a {really} long string that needs to be split without a doubt (i.e."
603 f" most definitely). In short, this {string} that can't possibly be {{expected}} to"
604 f" fit all together on one line. In {fact} it may even take up three or more"
605 " lines... like four or five... but probably just four."
608 long_unmergable_string_with_pragma = (
609 "This is a really long string that can't be merged because it has a likely pragma at the end" # type: ignore
613 long_unmergable_string_with_pragma = (
614 "This is a really long string that can't be merged because it has a likely pragma at the end" # noqa
618 long_unmergable_string_with_pragma = (
619 "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
623 string_with_nameescape = (
624 "........................................................................"
628 string_with_nameescape = (
629 "..........................................................................."
633 string_with_nameescape = (
634 "............................................................................"
638 string_with_nameescape_and_escaped_backslash = (
639 "......................................................................"
643 string_with_nameescape_and_escaped_backslash = (
644 "........................................................................."
648 string_with_nameescape_and_escaped_backslash = (
649 ".........................................................................."
653 string_with_escaped_nameescape = (
654 "........................................................................ \\N{LAO"
658 string_with_escaped_nameescape = (
659 "..........................................................................."