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
215 "This is a really long string that can't possibly be expected to fit all together"
216 " on one line. In fact it may even take up three or more lines... like four or"
217 " five... but probably just three."
221 "This is a really long string that can't possibly be expected to fit all together"
222 " on one line. In fact it may even take up three or more lines... like four or"
223 " five... but probably just three."
229 "This is a really long string inside of a print statement with extra arguments"
230 " attached at the end of it.",
237 "This is a really long string inside of a print statement with no extra arguments"
238 " attached at the end of it."
243 "This is a really long string that can't possibly be expected to fit all"
244 " together on one line. Also it is inside a dictionary, so formatting is more"
248 "This is another really really (not really) long string that also can't be"
249 " expected to fit on one line and is, like the other string, inside a"
256 "This is a really long string that can't possibly be expected to fit all"
257 " together on one line. Also it is inside a dictionary, so formatting is more"
261 "This is another really really (not really) long string that also can't be"
262 " expected to fit on one line and is, like the other string, inside a"
269 "This is a really long string that can't possibly be expected to fit all"
270 " together on one line. Also it is inside a dictionary, so formatting is more"
274 "This is another really really (not really) long string that also can't be"
275 " expected to fit on one line and is, like the other string, inside a"
281 "A long and ridiculous {}".format(string_key): (
282 "This is a really really really long string that has to go i,side of a"
283 " dictionary. It is soooo bad."
285 some_func("calling", "some", "stuff"): (
286 "This is a really really really long string that has to go inside of a"
287 " dictionary. It is {soooo} bad (#{x}).".format(sooo="soooo", x=2)
290 % ("formatted", "string"): (
291 "This is a really really really long string that has to go inside of a"
292 " dictionary. It is %s bad (#%d)."
300 "Long keyword strings also need to be wrapped, but they will probably need to"
301 " be handled a little bit differently."
306 "But what should happen when code has already been formatted but in the wrong way?"
307 " Like with a space at the end instead of the beginning. Or what about when it is"
312 "But what should happen when code has already "
313 "been formatted but in the wrong way? Like "
314 "with a space at the end instead of the "
315 "beginning. Or what about when it is split too "
316 "soon? In the case of a split that is too "
317 "short, black will try to honer the custom "
322 "What if we have inline comments on " # First Comment
323 "each line of a bad split? In that " # Second Comment
324 "case, we should just leave it alone." # Third Comment
328 "But what should happen when code has already "
329 "been formatted but in the wrong way? Like "
330 "with a space at the end instead of the "
331 "beginning. Or what about when it is split too "
332 "soon? In the case of a split that is too "
333 "short, black will try to honer the custom "
345 "But what should happen when code has already been formatted but in the wrong"
346 " way? Like with a space at the end instead of the beginning. Or what about"
347 " when it is split too soon?"
353 "But what should happen when code has already "
354 r"been formatted but in the wrong way? Like "
355 "with a space at the end instead of the "
356 r"beginning. Or what about when it is split too "
357 r"soon? In the case of a split that is too "
358 "short, black will try to honer the custom "
367 r"This is a long raw string. When re-formatting this string, black needs to make"
368 r" sure it prepends the 'r' onto the new string."
372 "We also need to be sure to preserve any and all {} which may or may not be"
373 " attached to the string in question.".format("method calls")
376 fmt_string2 = "But what about when the string is {} but {}".format(
378 "the method call is really really really really really really really really long?",
382 "While we are on the topic of %s, we should also note that old-style formatting"
383 " must also be preserved, since some %s still uses it." % ("formatting", "code")
386 old_fmt_string2 = "This is a %s %s %s %s" % (
387 "really really really really really",
389 "way to format strings!",
390 "Use f-strings instead!",
394 "Whereas only the strings after the percent sign were long in the last example,"
395 " this example uses a long initial string as well. This is another %s %s %s %s"
397 "really really really really really",
399 "way to format strings!",
400 "Use f-strings instead!",
405 f"f-strings definitely make things more {difficult} than they need to be for"
406 " {black}. But boy they sure are handy. The problem is that some lines will need"
407 f" to have the 'f' whereas others do not. This {line}, for example, needs one."
410 fstring_with_no_fexprs = (
411 f"Some regular string that needs to get split certainly but is NOT an fstring by"
412 f" any means whatsoever."
415 comment_string = ( # This comment gets thrown to the top.
416 "Long lines with inline comments should have their comments appended to the"
417 " reformatted string's enclosing right parentheses."
420 arg_comment_string = print(
421 "Long lines with inline comments which are apart of (and not the only member of) an"
422 " argument list should have their comments appended to the reformatted string's"
423 " enclosing left parentheses.", # This comment stays on the bottom.
430 pragma_comment_string1 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa: E501
432 pragma_comment_string2 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa
434 """This is a really really really long triple quote string and it should not be touched."""
436 triple_quote_string = """This is a really really really long triple quote string assignment and it should not be touched."""
438 assert some_type_of_boolean_expression, (
439 "Followed by a really really really long string that is used to provide context to"
440 " the AssertionError exception."
443 assert some_type_of_boolean_expression, (
444 "Followed by a really really really long string that is used to provide context to"
445 " the AssertionError exception, which uses dynamic string {}.".format("formatting")
448 assert some_type_of_boolean_expression, (
449 "Followed by a really really really long string that is used to provide context to"
450 " the AssertionError exception, which uses dynamic string %s." % "formatting"
453 assert some_type_of_boolean_expression, (
454 "Followed by a really really really long string that is used to provide context to"
455 " the AssertionError exception, which uses dynamic %s %s."
456 % ("string", "formatting")
460 "With a reallly generic name and with a really really long string that is, at some"
461 " point down the line, "
463 + " to a variable and then added to another string."
467 "With a reallly generic name and with a really really long string that is, at some"
468 " point down the line, "
470 + " to a variable and then added to another string. But then what happens when the"
471 " final string is also supppppperrrrr long?! Well then that second (realllllllly"
472 " long) string should be split too.",
473 "and a second argument",
478 "A really really really really really really really really really really really"
479 " really really long {} {}".format("return", "value")
483 "This is a really long string argument to a function that has a trailing comma"
484 " which should NOT be there.",
488 "This is a really long string argument to a function that has a trailing comma"
489 " which should NOT be there.", # comment after comma
493 "This is a really long string argument to a function that has a trailing comma"
494 " which should NOT be there.",
498 "This is a really long string argument to a function that has a trailing comma"
499 " which should NOT be there.", # comment after comma
502 func_with_bad_parens_that_wont_fit_in_one_line(
503 "short string that should have parens stripped", x, y, z
506 func_with_bad_parens_that_wont_fit_in_one_line(
507 x, y, "short string that should have parens stripped", z
510 func_with_bad_parens(
511 "short string that should have parens stripped",
517 func_with_bad_parens(
520 "short string that should have parens stripped",
524 annotated_variable: Final = (
529 + "using the '+' operator."
531 annotated_variable: Final = (
532 "This is a large string that has a type annotation attached to it. A type"
533 " annotation should NOT stop a long string from being wrapped."
535 annotated_variable: Literal["fakse_literal"] = (
536 "This is a large string that has a type annotation attached to it. A type"
537 " annotation should NOT stop a long string from being wrapped."
541 "This is a really long string with \"embedded\" double quotes and 'single' quotes"
542 " that also handles checking for an even number of backslashes \\"
545 "This is a really long string with \"embedded\" double quotes and 'single' quotes"
546 " that also handles checking for an even number of backslashes \\\\"
549 "This is a really 'long' string with \"embedded double quotes\" and 'single' quotes"
550 ' that also handles checking for an odd number of backslashes \\", like'
554 short_string = "Hi there."
556 func_call(short_string="Hi there.")
558 raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
563 "This is a really long string that can't possibly be expected to fit all"
564 " together on one line. In fact it may even take up three or more lines... like"
565 " four or five... but probably just three."
570 "This is a {really} long string that needs to be split without a doubt (i.e."
571 f" most definitely). In short, this {string} that can't possibly be {{expected}} to"
572 f" fit all together on one line. In {fact} it may even take up three or more"
573 " lines... like four or five... but probably just four."
576 long_unmergable_string_with_pragma = (
577 "This is a really long string that can't be merged because it has a likely pragma at the end" # type: ignore
581 long_unmergable_string_with_pragma = (
582 "This is a really long string that can't be merged because it has a likely pragma at the end" # noqa
586 long_unmergable_string_with_pragma = (
587 "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