Debian Codegraph @

tests/data/cases/long_strings_flag_disabled.py

raw
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."
2
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."
4
5 y = "Short string"
6
7 print(
8 "This is a really long string inside of a print statement with extra arguments attached at the end of it.",
9 x,
10 y,
11 z,
12 )
13
14 print(
15 "This is a really long string inside of a print statement with no extra arguments attached at the end of it."
16 )
17
18 D1 = {
19 "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.",
20 "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.",
21 }
22
23 D2 = {
24 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.",
25 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.",
26 }
27
28 D3 = {
29 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.",
30 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.",
31 }
32
33 D4 = {
34 "A long and ridiculous {}".format(
35 string_key
36 ): "This is a really really really long string that has to go i,side of a dictionary. It is soooo bad.",
37 some_func(
38 "calling", "some", "stuff"
39 ): "This is a really really really long string that has to go inside of a dictionary. It is {soooo} bad (#{x}).".format(
40 sooo="soooo", x=2
41 ),
42 "A %s %s"
43 % (
44 "formatted",
45 "string",
46 ): (
47 "This is a really really really long string that has to go inside of a dictionary. It is %s bad (#%d)."
48 % ("soooo", 2)
49 ),
50 }
51
52 func_with_keywords(
53 my_arg,
54 my_kwarg="Long keyword strings also need to be wrapped, but they will probably need to be handled a little bit differently.",
55 )
56
57 bad_split1 = (
58 "But what should happen when code has already been formatted but in the wrong way? Like"
59 " with a space at the end instead of the beginning. Or what about when it is split too soon?"
60 )
61
62 bad_split2 = (
63 "But what should happen when code has already "
64 "been formatted but in the wrong way? Like "
65 "with a space at the end instead of the "
66 "beginning. Or what about when it is split too "
67 "soon? In the case of a split that is too "
68 "short, black will try to honer the custom "
69 "split."
70 )
71
72 bad_split3 = (
73 "What if we have inline comments on " # First Comment
74 "each line of a bad split? In that " # Second Comment
75 "case, we should just leave it alone." # Third Comment
76 )
77
78 bad_split_func1(
79 "But what should happen when code has already "
80 "been formatted but in the wrong way? Like "
81 "with a space at the end instead of the "
82 "beginning. Or what about when it is split too "
83 "soon? In the case of a split that is too "
84 "short, black will try to honer the custom "
85 "split.",
86 xxx,
87 yyy,
88 zzz,
89 )
90
91 bad_split_func2(
92 xxx,
93 yyy,
94 zzz,
95 long_string_kwarg="But what should happen when code has already been formatted but in the wrong way? Like "
96 "with a space at the end instead of the beginning. Or what about when it is split too "
97 "soon?",
98 )
99
100 bad_split_func3(
101 (
102 "But what should happen when code has already "
103 r"been formatted but in the wrong way? Like "
104 "with a space at the end instead of the "
105 r"beginning. Or what about when it is split too "
106 r"soon? In the case of a split that is too "
107 "short, black will try to honer the custom "
108 "split."
109 ),
110 xxx,
111 yyy,
112 zzz,
113 )
114
115 raw_string = r"This is a long raw string. When re-formatting this string, black needs to make sure it prepends the 'r' onto the new string."
116
117 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(
118 "method calls"
119 )
120
121 fmt_string2 = "But what about when the string is {} but {}".format(
122 "short",
123 "the method call is really really really really really really really really long?",
124 )
125
126 old_fmt_string1 = (
127 "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."
128 % ("formatting", "code")
129 )
130
131 old_fmt_string2 = "This is a %s %s %s %s" % (
132 "really really really really really",
133 "old",
134 "way to format strings!",
135 "Use f-strings instead!",
136 )
137
138 old_fmt_string3 = (
139 "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"
140 % (
141 "really really really really really",
142 "old",
143 "way to format strings!",
144 "Use f-strings instead!",
145 )
146 )
147
148 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."
149
150 fstring_with_no_fexprs = f"Some regular string that needs to get split certainly but is NOT an fstring by any means whatsoever."
151
152 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.
153
154 arg_comment_string = print(
155 "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.
156 "Arg #2",
157 "Arg #3",
158 "Arg #4",
159 "Arg #5",
160 )
161
162 pragma_comment_string1 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa: E501
163
164 pragma_comment_string2 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone." # noqa
165
166 """This is a really really really long triple quote string and it should not be touched."""
167
168 triple_quote_string = """This is a really really really long triple quote string assignment and it should not be touched."""
169
170 assert (
171 some_type_of_boolean_expression
172 ), "Followed by a really really really long string that is used to provide context to the AssertionError exception."
173
174 assert (
175 some_type_of_boolean_expression
176 ), "Followed by a really really really long string that is used to provide context to the AssertionError exception, which uses dynamic string {}.".format(
177 "formatting"
178 )
179
180 assert some_type_of_boolean_expression, (
181 "Followed by a really really really long string that is used to provide context to the AssertionError exception, which uses dynamic string %s."
182 % "formatting"
183 )
184
185 assert some_type_of_boolean_expression, (
186 "Followed by a really really really long string that is used to provide context to the AssertionError exception, which uses dynamic %s %s."
187 % ("string", "formatting")
188 )
189
190 some_function_call(
191 "With a reallly generic name and with a really really long string that is, at some point down the line, "
192 + added
193 + " to a variable and then added to another string."
194 )
195
196 some_function_call(
197 "With a reallly generic name and with a really really long string that is, at some point down the line, "
198 + added
199 + " 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.",
200 "and a second argument",
201 and_a_third,
202 )
203
204 return "A really really really really really really really really really really really really really long {} {}".format(
205 "return", "value"
206 )
207
208 func_with_bad_comma(
209 "This is a really long string argument to a function that has a trailing comma which should NOT be there.",
210 )
211
212 func_with_bad_comma(
213 "This is a really long string argument to a function that has a trailing comma which should NOT be there.", # comment after comma
214 )
215
216 func_with_bad_comma(
217 (
218 "This is a really long string argument to a function that has a trailing comma"
219 " which should NOT be there."
220 ),
221 )
222
223 func_with_bad_comma(
224 (
225 "This is a really long string argument to a function that has a trailing comma"
226 " which should NOT be there."
227 ), # comment after comma
228 )
229
230 func_with_bad_parens_that_wont_fit_in_one_line(
231 ("short string that should have parens stripped"), x, y, z
232 )
233
234 func_with_bad_parens_that_wont_fit_in_one_line(
235 x, y, ("short string that should have parens stripped"), z
236 )
237
238 func_with_bad_parens(
239 ("short string that should have parens stripped"),
240 x,
241 y,
242 z,
243 )
244
245 func_with_bad_parens(
246 x,
247 y,
248 ("short string that should have parens stripped"),
249 z,
250 )
251
252 annotated_variable: Final = (
253 "This is a large "
254 + STRING
255 + " that has been "
256 + CONCATENATED
257 + "using the '+' operator."
258 )
259 annotated_variable: Final = (
260 "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."
261 )
262 annotated_variable: Literal["fakse_literal"] = (
263 "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."
264 )
265
266 backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\"
267 backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\\\"
268 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...\\\\\\"
269
270 short_string = "Hi" " there."
271
272 func_call(short_string=("Hi" " there."))
273
274 raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
275
276
277 def foo():
278 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."
279
280
281 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."
282
283 long_unmergable_string_with_pragma = (
284 "This is a really long string that can't be merged because it has a likely pragma at the end" # type: ignore
285 " of it."
286 )
287
288 long_unmergable_string_with_pragma = (
289 "This is a really long string that can't be merged because it has a likely pragma at the end" # noqa
290 " of it."
291 )
292
293 long_unmergable_string_with_pragma = (
294 "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
295 " of it."
296 )