1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954
|
# flags: --unstable
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."
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."
y = (
'Short string'
)
print('This is a really long string inside of a print statement with extra arguments attached at the end of it.', x, y, z)
print("This is a really long string inside of a print statement with no extra arguments attached at the end of it.")
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."}
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."}
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."}
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)}
D5 = { # Test for https://github.com/psf/black/issues/3261
("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"},
}
D6 = { # Test for https://github.com/psf/black/issues/3261
("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"],
}
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 splitting 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")]
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."]
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 splitting 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")}
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."}
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 splitting 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"))
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.",)
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.")
bad_split1 = (
'But what should happen when code has already been formatted but in the wrong way? Like'
" with a space at the end instead of the beginning. Or what about when it is split too soon?"
)
bad_split2 = "But what should happen when code has already " \
"been formatted but in the wrong way? Like " \
"with a space at the end instead of the " \
"beginning. Or what about when it is split too " \
"soon? In the case of a split that is too " \
"short, black will try to honer the custom " \
"split."
bad_split3 = (
"What if we have inline comments on " # First Comment
"each line of a bad split? In that " # Second Comment
"case, we should just leave it alone." # Third Comment
)
bad_split_func1(
"But what should happen when code has already "
"been formatted but in the wrong way? Like "
"with a space at the end instead of the "
"beginning. Or what about when it is split too "
"soon? In the case of a split that is too "
"short, black will try to honer the custom "
"split.",
xxx, yyy, zzz
)
bad_split_func2(
xxx, yyy, zzz,
long_string_kwarg="But what should happen when code has already been formatted but in the wrong way? Like "
"with a space at the end instead of the beginning. Or what about when it is split too "
"soon?",
)
bad_split_func3(
(
"But what should happen when code has already "
r"been formatted but in the wrong way? Like "
"with a space at the end instead of the "
r"beginning. Or what about when it is split too "
r"soon? In the case of a split that is too "
"short, black will try to honer the custom "
"split."
),
xxx,
yyy,
zzz,
)
inline_comments_func1(
"if there are inline "
"comments in the middle "
# Here is the standard alone comment.
"of the implicitly concatenated "
"string, we should handle "
"them correctly",
xxx,
)
inline_comments_func2(
"what if the string is very very very very very very very very very very long and this part does "
"not fit into a single line? "
# Here is the standard alone comment.
"then the string should still be properly handled by merging and splitting "
"it into parts that fit in line length.",
xxx,
)
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."
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")
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?")
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")
old_fmt_string2 = "This is a %s %s %s %s" % ("really really really really really", "old", "way to format strings!", "Use f-strings instead!")
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!")
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."
fstring_with_no_fexprs = f"Some regular string that needs to get split certainly but is NOT an fstring by any means whatsoever."
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.
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.
"Arg #2", "Arg #3", "Arg #4", "Arg #5")
pragma_comment_string1 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa: E501
pragma_comment_string2 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa
"""This is a really really really long triple quote string and it should not be touched."""
triple_quote_string = """This is a really really really long triple quote string assignment and it should not be touched."""
assert some_type_of_boolean_expression, "Followed by a really really really long string that is used to provide context to the AssertionError exception."
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")
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"
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")
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.")
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)
return "A really really really really really really really really really really really really really long {} {}".format("return", "value")
func_with_bad_comma(
"This is a really long string argument to a function that has a trailing comma which should NOT be there.",
)
func_with_bad_comma(
"This is a really long string argument to a function that has a trailing comma which should NOT be there.", # comment after comma
)
func_with_bad_comma(
(
"This is a really long string argument to a function that has a trailing comma"
" which should NOT be there."
),
)
func_with_bad_comma(
(
"This is a really long string argument to a function that has a trailing comma"
" which should NOT be there."
), # comment after comma
)
func_with_bad_parens_that_wont_fit_in_one_line(
("short string that should have parens stripped"),
x,
y,
z
)
func_with_bad_parens_that_wont_fit_in_one_line(
x,
y,
("short string that should have parens stripped"),
z
)
func_with_bad_parens(
("short string that should have parens stripped"),
x,
y,
z,
)
func_with_bad_parens(
x,
y,
("short string that should have parens stripped"),
z,
)
annotated_variable: Final = "This is a large " + STRING + " that has been " + CONCATENATED + "using the '+' operator."
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."
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."
backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\"
backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\\\"
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...\\\\\\"
short_string = (
"Hi"
" there."
)
func_call(
short_string=(
"Hi"
" there."
)
)
raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
def foo():
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."
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."
long_unmergable_string_with_pragma = (
"This is a really long string that can't be merged because it has a likely pragma at the end" # type: ignore
" of it."
)
long_unmergable_string_with_pragma = (
"This is a really long string that can't be merged because it has a likely pragma at the end" # noqa
" of it."
)
long_unmergable_string_with_pragma = (
"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
" of it."
)
string_with_nameescape = (
"........................................................................ \N{LAO KO LA}"
)
string_with_nameescape = (
"........................................................................... \N{LAO KO LA}"
)
string_with_nameescape = (
"............................................................................ \N{LAO KO LA}"
)
string_with_nameescape_and_escaped_backslash = (
"...................................................................... \\\N{LAO KO LA}"
)
string_with_nameescape_and_escaped_backslash = (
"......................................................................... \\\N{LAO KO LA}"
)
string_with_nameescape_and_escaped_backslash = (
".......................................................................... \\\N{LAO KO LA}"
)
string_with_escaped_nameescape = (
"........................................................................ \\N{LAO KO LA}"
)
string_with_escaped_nameescape = (
"........................................................................... \\N{LAO KO LA}"
)
msg = lambda x: f"this is a very very very very long lambda value {x} that doesn't fit on a single line"
dict_with_lambda_values = {
"join": lambda j: (
f"{j.__class__.__name__}({some_function_call(j.left)}, "
f"{some_function_call(j.right)})"
),
}
# Complex string concatenations with a method call in the middle.
code = (
(" return [\n")
+ (
", \n".join(
" (%r, self.%s, visitor.%s)"
% (attrname, attrname, visit_name)
for attrname, visit_name in names
)
)
+ ("\n ]\n")
)
# Test case of an outer string' parens enclose an inner string's parens.
call(body=("%s %s" % ((",".join(items)), suffix)))
log.info(f'Skipping: {desc["db_id"]=} {desc["ms_name"]} {money=} {dte=} {pos_share=} {desc["status"]=} {desc["exposure_max"]=}')
log.info(f"Skipping: {desc['db_id']=} {desc['ms_name']} {money=} {dte=} {pos_share=} {desc['status']=} {desc['exposure_max']=}")
log.info(f'Skipping: {desc["db_id"]} {foo("bar",x=123)} {"foo" != "bar"} {(x := "abc=")} {pos_share=} {desc["status"]} {desc["exposure_max"]}')
log.info(f'Skipping: {desc["db_id"]} {desc["ms_name"]} {money=} {(x := "abc=")=} {pos_share=} {desc["status"]} {desc["exposure_max"]}')
log.info(f'Skipping: {desc["db_id"]} {foo("bar",x=123)=} {money=} {dte=} {pos_share=} {desc["status"]} {desc["exposure_max"]}')
log.info(f'Skipping: {foo("asdf")=} {desc["ms_name"]} {money=} {dte=} {pos_share=} {desc["status"]} {desc["exposure_max"]}')
log.info(f'Skipping: {"a" == "b" == "c" == "d"} {desc["ms_name"]} {money=} {dte=} {pos_share=} {desc["status"]} {desc["exposure_max"]}')
log.info(f'Skipping: {"a" == "b" == "c" == "d"=} {desc["ms_name"]} {money=} {dte=} {pos_share=} {desc["status"]} {desc["exposure_max"]}')
log.info(f'Skipping: { longer_longer_longer_longer_longer_longer_name [ "db_id" ] [ "another_key" ] = : .3f }')
log.info(f'''Skipping: {"a" == 'b'} {desc["ms_name"]} {money=} {dte=} {pos_share=} {desc["status"]} {desc["exposure_max"]}''')
log.info(f'''Skipping: {'a' == "b"=} {desc["ms_name"]} {money=} {dte=} {pos_share=} {desc["status"]} {desc["exposure_max"]}''')
log.info(f"""Skipping: {'a' == 'b'} {desc['ms_name']} {money=} {dte=} {pos_share=} {desc['status']} {desc['exposure_max']}""")
x = {
"xx_xxxxx_xxxxxxxxxx_xxxxxxxxx_xx": (
"xx:xxxxxxxxxxxxxxxxx_xxxxx_xxxxxxx_xxxxxxxxxxx{xx}xxx_xxxxx_xxxxxxxxx_xxxxxxxxxxxx_xxxx"
)
}
x = {
"xx_xxxxx_xxxxxxxxxx_xxxxxxxxx_xx": "xx:xxxxxxxxxxxxxxxxx_xxxxx_xxxxxxx_xxxxxxxxxxx{xx}xxx_xxxxx_xxxxxxxxx_xxxxxxxxxxxx_xxxx",
}
x = {
"xx_xxxxx_xxxxxxxxxx_xxxxxxxxx_xx": (
"xx:xxxxxxxxxxxxxxxxx_xxxxx_xxxxxxx_xxxxxxxxxx"
)
}
# output
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."
)
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."
)
y = "Short string"
print(
"This is a really long string inside of a print statement with extra arguments"
" attached at the end of it.",
x,
y,
z,
)
print(
"This is a really long string inside of a print statement with no extra arguments"
" attached at the end of it."
)
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."
),
}
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."
),
}
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."
),
}
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)
),
}
D5 = { # Test for https://github.com/psf/black/issues/3261
"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"
},
}
D6 = { # Test for https://github.com/psf/black/issues/3261
"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",
],
}
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 splitting 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",
]
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."
]
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 splitting 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",
}
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."
}
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 splitting 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",
)
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."
),
)
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."
),
)
bad_split1 = (
"But what should happen when code has already been formatted but in the wrong way?"
" Like with a space at the end instead of the beginning. Or what about when it is"
" split too soon?"
)
bad_split2 = (
"But what should happen when code has already "
"been formatted but in the wrong way? Like "
"with a space at the end instead of the "
"beginning. Or what about when it is split too "
"soon? In the case of a split that is too "
"short, black will try to honer the custom "
"split."
)
bad_split3 = (
"What if we have inline comments on " # First Comment
"each line of a bad split? In that " # Second Comment
"case, we should just leave it alone." # Third Comment
)
bad_split_func1(
"But what should happen when code has already "
"been formatted but in the wrong way? Like "
"with a space at the end instead of the "
"beginning. Or what about when it is split too "
"soon? In the case of a split that is too "
"short, black will try to honer the custom "
"split.",
xxx,
yyy,
zzz,
)
bad_split_func2(
xxx,
yyy,
zzz,
long_string_kwarg=(
"But what should happen when code has already been formatted but in the wrong"
" way? Like with a space at the end instead of the beginning. Or what about"
" when it is split too soon?"
),
)
bad_split_func3(
(
"But what should happen when code has already "
r"been formatted but in the wrong way? Like "
"with a space at the end instead of the "
r"beginning. Or what about when it is split too "
r"soon? In the case of a split that is too "
"short, black will try to honer the custom "
"split."
),
xxx,
yyy,
zzz,
)
inline_comments_func1(
"if there are inline comments in the middle "
# Here is the standard alone comment.
"of the implicitly concatenated string, we should handle them correctly",
xxx,
)
inline_comments_func2(
"what if the string is very very very very very very very very very very long and"
" this part does not fit into a single line? "
# Here is the standard alone comment.
"then the string should still be properly handled by merging and splitting "
"it into parts that fit in line length.",
xxx,
)
raw_string = (
r"This is a long raw string. When re-formatting this string, black needs to make"
r" sure it prepends the 'r' onto the new string."
)
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")
)
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?",
)
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")
)
old_fmt_string2 = "This is a %s %s %s %s" % (
"really really really really really",
"old",
"way to format strings!",
"Use f-strings instead!",
)
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!",
)
)
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"
f" to have the 'f' whereas others do not. This {line}, for example, needs one."
)
fstring_with_no_fexprs = (
f"Some regular string that needs to get split certainly but is NOT an fstring by"
f" any means whatsoever."
)
comment_string = ( # This comment gets thrown to the top.
"Long lines with inline comments should have their comments appended to the"
" reformatted string's enclosing right parentheses."
)
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.
"Arg #2",
"Arg #3",
"Arg #4",
"Arg #5",
)
pragma_comment_string1 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa: E501
pragma_comment_string2 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa
"""This is a really really really long triple quote string and it should not be touched."""
triple_quote_string = """This is a really really really long triple quote string assignment and it should not be touched."""
assert some_type_of_boolean_expression, (
"Followed by a really really really long string that is used to provide context to"
" the AssertionError exception."
)
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")
)
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"
)
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")
)
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."
)
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,
)
return (
"A really really really really really really really really really really really"
" really really long {} {}".format("return", "value")
)
func_with_bad_comma(
"This is a really long string argument to a function that has a trailing comma"
" which should NOT be there.",
)
func_with_bad_comma(
"This is a really long string argument to a function that has a trailing comma"
" which should NOT be there.", # comment after comma
)
func_with_bad_comma(
"This is a really long string argument to a function that has a trailing comma"
" which should NOT be there.",
)
func_with_bad_comma(
"This is a really long string argument to a function that has a trailing comma"
" which should NOT be there.", # comment after comma
)
func_with_bad_parens_that_wont_fit_in_one_line(
"short string that should have parens stripped", x, y, z
)
func_with_bad_parens_that_wont_fit_in_one_line(
x, y, "short string that should have parens stripped", z
)
func_with_bad_parens(
"short string that should have parens stripped",
x,
y,
z,
)
func_with_bad_parens(
x,
y,
"short string that should have parens stripped",
z,
)
annotated_variable: Final = (
"This is a large "
+ STRING
+ " that has been "
+ CONCATENATED
+ "using the '+' operator."
)
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."
)
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."
)
backslashes = (
"This is a really long string with \"embedded\" double quotes and 'single' quotes"
" that also handles checking for an even number of backslashes \\"
)
backslashes = (
"This is a really long string with \"embedded\" double quotes and 'single' quotes"
" that also handles checking for an even number of backslashes \\\\"
)
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...\\\\\\"
)
short_string = "Hi there."
func_call(short_string="Hi there.")
raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
def foo():
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."
)
x = (
"This is a {really} long string that needs to be split without a doubt (i.e."
f" most definitely). In short, this {string} that can't possibly be {{expected}} to"
f" 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."
)
long_unmergable_string_with_pragma = (
"This is a really long string that can't be merged because it has a likely pragma at the end" # type: ignore
" of it."
)
long_unmergable_string_with_pragma = (
"This is a really long string that can't be merged because it has a likely pragma at the end" # noqa
" of it."
)
long_unmergable_string_with_pragma = (
"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
" of it."
)
string_with_nameescape = (
"........................................................................"
" \N{LAO KO LA}"
)
string_with_nameescape = (
"..........................................................................."
" \N{LAO KO LA}"
)
string_with_nameescape = (
"............................................................................"
" \N{LAO KO LA}"
)
string_with_nameescape_and_escaped_backslash = (
"......................................................................"
" \\\N{LAO KO LA}"
)
string_with_nameescape_and_escaped_backslash = (
"........................................................................."
" \\\N{LAO KO LA}"
)
string_with_nameescape_and_escaped_backslash = (
".........................................................................."
" \\\N{LAO KO LA}"
)
string_with_escaped_nameescape = (
"........................................................................ \\N{LAO"
" KO LA}"
)
string_with_escaped_nameescape = (
"..........................................................................."
" \\N{LAO KO LA}"
)
msg = lambda x: (
f"this is a very very very very long lambda value {x} that doesn't fit on a"
" single line"
)
dict_with_lambda_values = {
"join": lambda j: (
f"{j.__class__.__name__}({some_function_call(j.left)}, "
f"{some_function_call(j.right)})"
),
}
# Complex string concatenations with a method call in the middle.
code = (
" return [\n"
+ ", \n".join(
" (%r, self.%s, visitor.%s)" % (attrname, attrname, visit_name)
for attrname, visit_name in names
)
+ "\n ]\n"
)
# Test case of an outer string' parens enclose an inner string's parens.
call(body="%s %s" % (",".join(items), suffix))
log.info(
f'Skipping: {desc["db_id"]=} {desc["ms_name"]} {money=} {dte=} {pos_share=}'
f' {desc["status"]=} {desc["exposure_max"]=}'
)
log.info(
f"Skipping: {desc['db_id']=} {desc['ms_name']} {money=} {dte=} {pos_share=}"
f" {desc['status']=} {desc['exposure_max']=}"
)
log.info(
f'Skipping: {desc["db_id"]} {foo("bar",x=123)} {"foo" != "bar"} {(x := "abc=")}'
f' {pos_share=} {desc["status"]} {desc["exposure_max"]}'
)
log.info(
f'Skipping: {desc["db_id"]} {desc["ms_name"]} {money=} {(x := "abc=")=}'
f' {pos_share=} {desc["status"]} {desc["exposure_max"]}'
)
log.info(
f'Skipping: {desc["db_id"]} {foo("bar",x=123)=} {money=} {dte=} {pos_share=}'
f' {desc["status"]} {desc["exposure_max"]}'
)
log.info(
f'Skipping: {foo("asdf")=} {desc["ms_name"]} {money=} {dte=} {pos_share=}'
f' {desc["status"]} {desc["exposure_max"]}'
)
log.info(
f'Skipping: {"a" == "b" == "c" == "d"} {desc["ms_name"]} {money=} {dte=}'
f' {pos_share=} {desc["status"]} {desc["exposure_max"]}'
)
log.info(
f'Skipping: {"a" == "b" == "c" == "d"=} {desc["ms_name"]} {money=} {dte=}'
f' {pos_share=} {desc["status"]} {desc["exposure_max"]}'
)
log.info(
"Skipping:"
f' { longer_longer_longer_longer_longer_longer_name [ "db_id" ] [ "another_key" ] = : .3f }'
)
log.info(
f"""Skipping: {"a" == 'b'} {desc["ms_name"]} {money=} {dte=} {pos_share=} {desc["status"]} {desc["exposure_max"]}"""
)
log.info(
f"""Skipping: {'a' == "b"=} {desc["ms_name"]} {money=} {dte=} {pos_share=} {desc["status"]} {desc["exposure_max"]}"""
)
log.info(
f"""Skipping: {'a' == 'b'} {desc['ms_name']} {money=} {dte=} {pos_share=} {desc['status']} {desc['exposure_max']}"""
)
x = {
"xx_xxxxx_xxxxxxxxxx_xxxxxxxxx_xx": (
"xx:xxxxxxxxxxxxxxxxx_xxxxx_xxxxxxx_xxxxxxxxxxx{xx}xxx_xxxxx_xxxxxxxxx_xxxxxxxxxxxx_xxxx"
)
}
x = {
"xx_xxxxx_xxxxxxxxxx_xxxxxxxxx_xx": (
"xx:xxxxxxxxxxxxxxxxx_xxxxx_xxxxxxx_xxxxxxxxxxx{xx}xxx_xxxxx_xxxxxxxxx_xxxxxxxxxxxx_xxxx"
),
}
x = {
"xx_xxxxx_xxxxxxxxxx_xxxxxxxxx_xx": "xx:xxxxxxxxxxxxxxxxx_xxxxx_xxxxxxx_xxxxxxxxxx"
}
|