Debian Codegraph @

tests/data/cases/preview_long_strings__regression.py

raw
1 # flags: --unstable
2 class A:
3 def foo():
4 result = type(message)("")
5
6
7 # Don't merge multiline (e.g. triple-quoted) strings.
8 def foo():
9 query = (
10 """SELECT xxxxxxxxxxxxxxxxxxxx(xxx)"""
11 """ FROM xxxxxxxxxxxxxxxx WHERE xxxxxxxxxx AND xxx <> xxxxxxxxxxxxxx()""")
12
13 # There was a bug where tuples were being identified as long strings.
14 long_tuple = ('Apple', 'Berry', 'Cherry', 'Dill', 'Evergreen', 'Fig',
15 'Grape', 'Harry', 'Iglu', 'Jaguar')
16
17 stupid_format_method_bug = "Some really long string that just so happens to be the {} {} to force the 'format' method to hang over the line length boundary. This is pretty annoying.".format("perfect", "length")
18
19 class A:
20 def foo():
21 os.system("This is a regression test. xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxxx.".format("xxxxxxxxxx", "xxxxxx", "xxxxxxxxxx"))
22
23
24 class A:
25 def foo():
26 XXXXXXXXXXXX.append(
27 (
28 "xxx_xxxxxxxxxx(xxxxx={}, xxxx={}, xxxxx, xxxx_xxxx_xxxxxxxxxx={})".format(
29 xxxxx, xxxx, xxxx_xxxx_xxxxxxxxxx
30 ),
31 my_var,
32 my_other_var,
33 )
34 )
35
36 class A:
37 class B:
38 def foo():
39 bar(
40 (
41 "[{}]: xxx_xxxxxxxxxx(xxxxx={}, xxxx={}, xxxxx={}"
42 " xxxx_xxxx_xxxxxxxxxx={}, xxxx={})"
43 .format(xxxx._xxxxxxxxxxxxxx, xxxxx, xxxx, xxxx_xxxx_xxxxxxxxxx, xxxxxxx)
44 ),
45 varX,
46 varY,
47 varZ,
48 )
49
50 def foo(xxxx):
51 for (xxx_xxxx, _xxx_xxx, _xxx_xxxxx, xxx_xxxx) in xxxx:
52 for xxx in xxx_xxxx:
53 assert ("x" in xxx) or (
54 xxx in xxx_xxx_xxxxx
55 ), "{0} xxxxxxx xx {1}, xxx {1} xx xxx xx xxxx xx xxx xxxx: xxx xxxx {2}".format(
56 xxx_xxxx, xxx, xxxxxx.xxxxxxx(xxx_xxx_xxxxx)
57 )
58
59 class A:
60 def disappearing_comment():
61 return (
62 ( # xx -x xxxxxxx xx xxx xxxxxxx.
63 '{{xxx_xxxxxxxxxx_xxxxxxxx}} xxx xxxx'
64 ' {} {{xxxx}} >&2'
65 .format(
66 "{xxxx} {xxxxxx}"
67 if xxxxx.xx_xxxxxxxxxx
68 else ( # Disappearing Comment
69 "--xxxxxxx --xxxxxx=x --xxxxxx-xxxxx=xxxxxx"
70 " --xxxxxx-xxxx=xxxxxxxxxxx.xxx"
71 )
72 )
73 ),
74 (x, y, z),
75 )
76
77 class A:
78 class B:
79 def foo():
80 xxxxx_xxxx(
81 xx, "\t"
82 "@xxxxxx '{xxxx_xxx}\t' > {xxxxxx_xxxx}.xxxxxxx;"
83 "{xxxx_xxx} >> {xxxxxx_xxxx}.xxxxxxx 2>&1; xx=$$?;"
84 "xxxx $$xx"
85 .format(xxxx_xxx=xxxx_xxxxxxx, xxxxxx_xxxx=xxxxxxx + "/" + xxxx_xxx_xxxx, x=xxx_xxxxx_xxxxx_xxx),
86 x,
87 y,
88 z,
89 )
90
91 func_call_where_string_arg_has_method_call_and_bad_parens(
92 (
93 "A long string with {}. This string is so long that it is ridiculous. It can't fit on one line at alllll.".format("formatting")
94 ),
95 )
96
97 func_call_where_string_arg_has_old_fmt_and_bad_parens(
98 (
99 "A long string with {}. This string is so long that it is ridiculous. It can't fit on one line at alllll." % "formatting"
100 ),
101 )
102
103 func_call_where_string_arg_has_old_fmt_and_bad_parens(
104 (
105 "A long string with {}. This {} is so long that it is ridiculous. It can't fit on one line at alllll." % ("formatting", "string")
106 ),
107 )
108
109 class A:
110 def append(self):
111 if True:
112 xxxx.xxxxxxx.xxxxx( ('xxxxxxxxxx xxxx xx xxxxxx(%x) xx %x xxxx xx xxx %x.xx'
113 % (len(self) + 1,
114 xxxx.xxxxxxxxxx,
115 xxxx.xxxxxxxxxx))
116 + (' %.3f (%s) to %.3f (%s).\n'
117 % (xxxx.xxxxxxxxx,
118 xxxx.xxxxxxxxxxxxxx(xxxx.xxxxxxxxx),
119 x,
120 xxxx.xxxxxxxxxxxxxx( xx)
121 )))
122
123 class A:
124 def foo():
125 some_func_call(
126 'xxxxxxxxxx',
127 (
128 "xx {xxxxxxxxxxx}/xxxxxxxxxxx.xxx xxxx.xxx && xxxxxx -x "
129 "\"xxxx xxxxxxx xxxxxx xxxx; xxxx xxxxxx_xxxxx xxxxxx xxxx; "
130 "xxxx.xxxx_xxxxxx(['xxxx.xxx'], xxxx.xxxxxxx().xxxxxxxxxx)\" "
131 ),
132 None,
133 ('xxxxxxxxxxx',),
134 ),
135
136 class A:
137 def foo():
138 some_func_call(
139 (
140 "xx {xxxxxxxxxxx}/xxxxxxxxxxx.xxx xxxx.xxx && xxxxxx -x "
141 "xxxx, ('xxxxxxx xxxxxx xxxx, xxxx') xxxxxx_xxxxx xxxxxx xxxx; "
142 "xxxx.xxxx_xxxxxx(['xxxx.xxx'], xxxx.xxxxxxx().xxxxxxxxxx)\" "
143 ),
144 None,
145 ('xxxxxxxxxxx',),
146 ),
147
148 xxxxxxx = { 'xx' : 'xxxx xxxxxxx xxxxxxxxx -x xxx -x /xxx/{0} -x xxx,xxx -xx {1} \
149 -xx {1} -xx xxx=xxx_xxxx,xxx_xx,xxx_xxx,xxx_xxxx,xxx_xx,xxx_xxx |\
150 xxxxxx -x xxxxxxxx -x xxxxxxxx -x',
151 'xx' : 'xxxx xxxxxxx xxxxxxxxx -x xxx -x /xxx/{0} -x xxx,xxx -xx {1} \
152 -xx {1} -xx xxx=xxx_xxxx_xxx_xxxx,xxx_xx_xxx_xxxx,xxx_xxxx_xxx_xxxx,\
153 xxx_xx_xxxx_xxxx,xxx_xxx_xxxx,xxx_xxx_xxxx xxxx=xxx | xxxxxx -x xxxxxxxx -x xxxxxxxx -x'
154 }
155
156 class A:
157 def foo(self):
158 if True:
159 xxxxx_xxxxxxxxxxxx('xxx xxxxxx xxx xxxxxxxxx.xx xx xxxxxxxx. xxx xxxxxxxxxxxxx.xx xxxxxxx '
160 + 'xx xxxxxx xxxxxx xxxxxx xx xxxxxxx xxx xxx ${0} xx x xxxxxxxx xxxxx'.xxxxxx(xxxxxx_xxxxxx_xxx))
161
162 class A:
163 class B:
164 def foo():
165 row = {
166 'xxxxxxxxxxxxxxx' : xxxxxx_xxxxx_xxxx,
167 # 'xxxxxxxxxxxxxxxxxxxxxxx'
168 # 'xxxxxxxxxxxxxxxxxxxxxx'
169 # 'xxxxxxxxxxxxxxxxxx'
170 # 'xxxxxxxxxxxxxxxxx'
171 'xxxxxxxxxx' : xxxxx_xxxxx,
172 }
173
174 class A:
175 def xxxx_xxx_xx_xxxxxxxxxx_xxxx_xxxxxxxxx(xxxx):
176 xxxxxxxx = [
177 xxxxxxxxxxxxxxxx(
178 'xxxx',
179 xxxxxxxxxxx={
180 'xxxx' : 1.0,
181 },
182 xxxxxx={'xxxxxx 1' : xxxxxx(xxxx='xxxxxx 1', xxxxxx=600.0)},
183 xxxxxxxx_xxxxxxx=0.0,
184 ),
185 xxxxxxxxxxxxxxxx(
186 'xxxxxxx',
187 xxxxxxxxxxx={
188 'xxxx' : 1.0,
189 },
190 xxxxxx={'xxxxxx 1' : xxxxxx(xxxx='xxxxxx 1', xxxxxx=200.0)},
191 xxxxxxxx_xxxxxxx=0.0,
192 ),
193 xxxxxxxxxxxxxxxx(
194 'xxxx',
195 ),
196 ]
197
198 some_dictionary = {
199 'xxxxx006': ['xxx-xxx xxxxx3xxxx1xx2xxxxxxxxxxxxxx0xx6xxxxxxxxxx2xxxxxx9xxxxxxxxxx0xxxxx1xxx2x/xx9xx6+x+xxxxxxxxxxxxxx4xxxxxxxxxxxxxxxxxxxxx43xxx2xx2x4x++xxx6xxxxxxxxx+xxxxx/xx9x+xxxxxxxxxxxxxx8x15xxxxxxxxxxxxxxxxx82xx/xxxxxxxxxxxxxx/x5xxxxxxxxxxxxxx6xxxxxx74x4/xxx4x+xxxxxxxxx2xxxxxxxx87xxxxx4xxxxxxxx3xx0xxxxx4xxx1xx9xx5xxxxxxx/xxxxx5xx6xx4xxxx1x/x2xxxxxxxxxxxx64xxxxxxx1x0xx5xxxxxxxxxxxxxx== xxxxx000 xxxxxxxxxx\n',
200 'xxx-xxx xxxxx3xxxx1xx2xxxxxxxxxxxxxx6xxxxxxxxxxxxxx9xxxxxxxxxxxxx3xxx9xxxxxxxxxxxxxxxx0xxxxxxxxxxxxxxxxx2xxxx2xxx6xxxxx/xx54xxxxxxxxx4xxx3xxxxxx9xx3xxxxx39xxxxxxxxx5xx91xxxx7xxxxxx8xxxxxxxxxxxxxxxx9xxx93xxxxxxxxxxxxxxxxx7xxx8xx8xx4/x1xxxxx1x3xxxxxxxxxxxxx3xxxxxx9xx4xx4x7xxxxxxxxxxxxx1xxxxxxxxx7xxxxxxxxxxxxxx4xx6xxxxxxxxx9xxx7xxxx2xxxxxxxxxxxxxxxxxxxxxx8xxxxxxxxxxxxxxxxxxxx6xx== xxxxx010 xxxxxxxxxx\n'],
201 'xxxxx016': ['xxx-xxx xxxxx3xxxx1xx2xxxxxxxxxxxxxx0xx6xxxxxxxxxx2xxxxxx9xxxxxxxxxx0xxxxx1xxx2x/xx9xx6+x+xxxxxxxxxxxxxx4xxxxxxxxxxxxxxxxxxxxx43xxx2xx2x4x++xxx6xxxxxxxxx+xxxxx/xx9x+xxxxxxxxxxxxxx8x15xxxxxxxxxxxxxxxxx82xx/xxxxxxxxxxxxxx/x5xxxxxxxxxxxxxx6xxxxxx74x4/xxx4x+xxxxxxxxx2xxxxxxxx87xxxxx4xxxxxxxx3xx0xxxxx4xxx1xx9xx5xxxxxxx/xxxxx5xx6xx4xxxx1x/x2xxxxxxxxxxxx64xxxxxxx1x0xx5xxxxxxxxxxxxxx== xxxxx000 xxxxxxxxxx\n',
202 'xxx-xxx xxxxx3xxxx1xx2xxxxxxxxxxxxxx6xxxxxxxxxxxxxx9xxxxxxxxxxxxx3xxx9xxxxxxxxxxxxxxxx0xxxxxxxxxxxxxxxxx2xxxx2xxx6xxxxx/xx54xxxxxxxxx4xxx3xxxxxx9xx3xxxxx39xxxxxxxxx5xx91xxxx7xxxxxx8xxxxxxxxxxxxxxxx9xxx93xxxxxxxxxxxxxxxxx7xxx8xx8xx4/x1xxxxx1x3xxxxxxxxxxxxx3xxxxxx9xx4xx4x7xxxxxxxxxxxxx1xxxxxxxxx7xxxxxxxxxxxxxx4xx6xxxxxxxxx9xxx7xxxx2xxxxxxxxxxxxxxxxxxxxxx8xxxxxxxxxxxxxxxxxxxx6xx== xxxxx010 xxxxxxxxxx\n']
203 }
204
205 def foo():
206 xxx_xxx = (
207 'xxxx xxx xxxxxxxx_xxxx xx "xxxxxxxxxx".'
208 '\n xxx: xxxxxx xxxxxxxx_xxxx=xxxxxxxxxx'
209 ) # xxxx xxxxxxxxxx xxxx xx xxxx xx xxx xxxxxxxx xxxxxx xxxxx.
210
211 some_tuple = ("some string", "some string" " which should be joined")
212
213 some_commented_string = ( # This comment stays at the top.
214 "This string is long but not so long that it needs hahahah toooooo be so greatttt"
215 " {} that I just can't think of any more good words to say about it at"
216 " allllllllllll".format("ha") # comments here are fine
217 )
218
219 some_commented_string = (
220 "This string is long but not so long that it needs hahahah toooooo be so greatttt" # But these
221 " {} that I just can't think of any more good words to say about it at" # comments will stay
222 " allllllllllll".format("ha") # comments here are fine
223 )
224
225 lpar_and_rpar_have_comments = func_call( # LPAR Comment
226 "Long really ridiculous type of string that shouldn't really even exist at all. I mean commmme onnn!!!", # Comma Comment
227 ) # RPAR Comment
228
229 cmd_fstring = (
230 f"sudo -E deluge-console info --detailed --sort-reverse=time_added "
231 f"{'' if ID is None else ID} | perl -nE 'print if /^{field}:/'"
232 )
233
234 cmd_fstring = f"sudo -E deluge-console info --detailed --sort-reverse=time_added {'' if ID is None else ID} | perl -nE 'print if /^{field}:/'"
235
236 cmd_fstring = f"sudo -E deluge-console info --detailed --sort-reverse=time_added {'{{}}' if ID is None else ID} | perl -nE 'print if /^{field}:/'"
237
238 cmd_fstring = f"sudo -E deluge-console info --detailed --sort-reverse=time_added {{'' if ID is None else ID}} | perl -nE 'print if /^{field}:/'"
239
240 fstring = f"This string really doesn't need to be an {{{{fstring}}}}, but this one most certainly, absolutely {does}."
241
242 fstring = (
243 f"We have to remember to escape {braces}."
244 " Like {these}."
245 f" But not {this}."
246 )
247
248 class A:
249 class B:
250 def foo():
251 st_error = STError(
252 f"This string ({string_leaf.value}) appears to be pointless (i.e. has"
253 " no parent)."
254 )
255
256 def foo():
257 user_regex = _lazy_re_compile(
258 r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*\Z" # dot-atom
259 r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"\Z)', # quoted-string
260 re.IGNORECASE)
261
262 def foo():
263 user_regex = _lazy_re_compile(
264 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # dot-atom
265 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', # quoted-string
266 xyz
267 )
268
269 def foo():
270 user_regex = _lazy_re_compile(
271 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # dot-atom
272 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', # quoted-string
273 xyz
274 )
275
276 class A:
277 class B:
278 def foo():
279 if not hasattr(module, name):
280 raise ValueError(
281 "Could not find object %s in %s.\n"
282 "Please note that you cannot serialize things like inner "
283 "classes. Please move the object into the main module "
284 "body to use migrations.\n"
285 "For more information, see "
286 "https://docs.djangoproject.com/en/%s/topics/migrations/#serializing-values"
287 % (name, module_name, get_docs_version()))
288
289 class A:
290 class B:
291 def foo():
292 if not hasattr(module, name):
293 raise ValueError(
294 "Could not find object %s in %s.\nPlease note that you cannot serialize things like inner classes. Please move the object into the main module body to use migrations.\nFor more information, see https://docs.djangoproject.com/en/%s/topics/migrations/#serializing-values"
295 % (name, module_name, get_docs_version()))
296
297 x = (
298 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
299 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
300 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
301 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
302 )
303
304 class Step(StepBase):
305 def who(self):
306 self.cmd = 'SR AAAA-CORRECT NAME IS {last_name} {first_name}{middle_name} {title}/P{passenger_association}'.format(
307 last_name=last_name,
308 first_name=first_name,
309 middle_name=middle_name,
310 title=title,
311 passenger_association=passenger_association,
312 )
313
314 xxxxxxx_xxxxxx_xxxxxxx = xxx(
315 [
316 xxxxxxxxxxxx(
317 xxxxxx_xxxxxxx=(
318 '((x.aaaaaaaaa = "xxxxxx.xxxxxxxxxxxxxxxxxxxxx") || (x.xxxxxxxxx = "xxxxxxxxxxxx")) && '
319 # xxxxx xxxxxxxxxxxx xxxx xxx (xxxxxxxxxxxxxxxx) xx x xxxxxxxxx xx xxxxxx.
320 "(x.bbbbbbbbbbbb.xxx != "
321 '"xxx:xxx:xxx::cccccccccccc:xxxxxxx-xxxx/xxxxxxxxxxx/xxxxxxxxxxxxxxxxx") && '
322 )
323 )
324 ]
325 )
326
327 if __name__ == "__main__":
328 for i in range(4, 8):
329 cmd = (
330 r"for pid in $(ps aux | grep paster | grep -v grep | grep '\-%d' | awk '{print $2}'); do kill $pid; done"
331 % (i)
332 )
333
334 def A():
335 def B():
336 def C():
337 def D():
338 def E():
339 def F():
340 def G():
341 assert (
342 c_float(val[0][0] / val[0][1]).value
343 == c_float(value[0][0] / value[0][1]).value
344 ), "%s didn't roundtrip" % tag
345
346 class xxxxxxxxxxxxxxxxxxxxx(xxxx.xxxxxxxxxxxxx):
347 def xxxxxxx_xxxxxx(xxxx):
348 assert xxxxxxx_xxxx in [
349 x.xxxxx.xxxxxx.xxxxx.xxxxxx,
350 x.xxxxx.xxxxxx.xxxxx.xxxx,
351 ], ("xxxxxxxxxxx xxxxxxx xxxx (xxxxxx xxxx) %x xxx xxxxx" % xxxxxxx_xxxx)
352
353 value.__dict__[
354 key
355 ] = "test" # set some Thrift field to non-None in the struct aa bb cc dd ee
356
357 RE_ONE_BACKSLASH = {
358 "asdf_hjkl_jkl": re.compile(
359 r"(?<!([0-9]\ ))(?<=(^|\ ))([A-Z]+(\ )?|[0-9](\ )|[a-z](\ )){4,7}([A-Z]|[0-9]|[a-z])($|\b)(?!(\ ?([0-9]\ )|(\.)))"
360 ),
361 }
362
363 RE_TWO_BACKSLASHES = {
364 "asdf_hjkl_jkl": re.compile(
365 r"(?<!([0-9]\ ))(?<=(^|\ ))([A-Z]+(\ )?|[0-9](\ )|[a-z](\\ )){4,7}([A-Z]|[0-9]|[a-z])($|\b)(?!(\ ?([0-9]\ )|(\.)))"
366 ),
367 }
368
369 RE_THREE_BACKSLASHES = {
370 "asdf_hjkl_jkl": re.compile(
371 r"(?<!([0-9]\ ))(?<=(^|\ ))([A-Z]+(\ )?|[0-9](\ )|[a-z](\\\ )){4,7}([A-Z]|[0-9]|[a-z])($|\b)(?!(\ ?([0-9]\ )|(\.)))"
372 ),
373 }
374
375 # We do NOT split on f-string expressions.
376 print(f"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam. {[f'{i}' for i in range(10)]}")
377 x = f"This is a long string which contains an f-expr that should not split {{{[i for i in range(5)]}}}."
378
379 # The parens should NOT be removed in this case.
380 (
381 "my very long string that should get formatted if I'm careful to make sure it goes"
382 " over 88 characters which it has now"
383 )
384
385 # The parens should NOT be removed in this case.
386 (
387 "my very long string that should get formatted if I'm careful to make sure it goes over 88 characters which"
388 " it has now"
389 )
390
391 # The parens should NOT be removed in this case.
392 (
393 "my very long string"
394 " that should get formatted"
395 " if I'm careful to make sure"
396 " it goes over 88 characters which"
397 " it has now"
398 )
399
400
401 def _legacy_listen_examples():
402 text += (
403 " \"listen for the '%(event_name)s' event\"\n"
404 "\n # ... (event logic logic logic) ...\n"
405 % {
406 "since": since,
407 }
408 )
409
410
411 class X:
412 async def foo(self):
413 msg = ""
414 for candidate in CANDIDATES:
415 msg += (
416 "**{candidate.object_type} {candidate.rev}**"
417 " - {candidate.description}\n"
418 )
419
420
421 temp_msg = (
422 f"{f'{humanize_number(pos)}.': <{pound_len+2}} "
423 f"{balance: <{bal_len + 5}} "
424 f"<<{author.display_name}>>\n"
425 )
426
427 assert str(suffix_arr) == (
428 "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', "
429 "'grykangaroo$', 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', "
430 "'o$', 'oo$', 'roo$', 'rykangaroo$', 'ykangaroo$']"
431 )
432 assert str(suffix_arr) != (
433 "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', "
434 "'grykangaroo$', 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', "
435 "'o$', 'oo$', 'roo$', 'rykangaroo$', 'ykangaroo$']"
436 )
437 assert str(suffix_arr) <= (
438 "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', "
439 "'grykangaroo$', 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', "
440 "'o$', 'oo$', 'roo$', 'rykangaroo$', 'ykangaroo$']"
441 )
442 assert str(suffix_arr) >= (
443 "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', "
444 "'grykangaroo$', 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', "
445 "'o$', 'oo$', 'roo$', 'rykangaroo$', 'ykangaroo$']"
446 )
447 assert str(suffix_arr) < (
448 "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', "
449 "'grykangaroo$', 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', "
450 "'o$', 'oo$', 'roo$', 'rykangaroo$', 'ykangaroo$']"
451 )
452 assert str(suffix_arr) > (
453 "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', "
454 "'grykangaroo$', 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', "
455 "'o$', 'oo$', 'roo$', 'rykangaroo$', 'ykangaroo$']"
456 )
457 assert str(suffix_arr) in "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', 'grykangaroo$', 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', 'o$', 'oo$', 'roo$', 'rykangaroo$', 'ykangaroo$']"
458 assert str(suffix_arr) not in "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', 'grykangaroo$', 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', 'o$', 'oo$', 'roo$', 'rykangaroo$', 'ykangaroo$']"
459 message = (
460 f"1. Go to Google Developers Console and log in with your Google account."
461 "(https://console.developers.google.com/)"
462 "2. You should be prompted to create a new project (name does not matter)."
463 "3. Click on Enable APIs and Services at the top."
464 "4. In the list of APIs choose or search for YouTube Data API v3 and "
465 "click on it. Choose Enable."
466 "5. Click on Credentials on the left navigation bar."
467 "6. Click on Create Credential at the top."
468 '7. At the top click the link for "API key".'
469 "8. No application restrictions are needed. Click Create at the bottom."
470 "9. You now have a key to add to `{prefix}set api youtube api_key`"
471 )
472 message = (
473 f"1. Go to Google Developers Console and log in with your Google account."
474 "(https://console.developers.google.com/)"
475 "2. You should be prompted to create a new project (name does not matter)."
476 f"3. Click on Enable APIs and Services at the top."
477 "4. In the list of APIs choose or search for YouTube Data API v3 and "
478 "click on it. Choose Enable."
479 f"5. Click on Credentials on the left navigation bar."
480 "6. Click on Create Credential at the top."
481 '7. At the top click the link for "API key".'
482 "8. No application restrictions are needed. Click Create at the bottom."
483 "9. You now have a key to add to `{prefix}set api youtube api_key`"
484 )
485 message = (
486 f"1. Go to Google Developers Console and log in with your Google account."
487 "(https://console.developers.google.com/)"
488 "2. You should be prompted to create a new project (name does not matter)."
489 f"3. Click on Enable APIs and Services at the top."
490 "4. In the list of APIs choose or search for YouTube Data API v3 and "
491 "click on it. Choose Enable."
492 f"5. Click on Credentials on the left navigation bar."
493 "6. Click on Create Credential at the top."
494 '7. At the top click the link for "API key".'
495 "8. No application restrictions are needed. Click Create at the bottom."
496 f"9. You now have a key to add to `{prefix}set api youtube api_key`"
497 )
498
499 # It shouldn't matter if the string prefixes are capitalized.
500 temp_msg = (
501 F"{F'{humanize_number(pos)}.': <{pound_len+2}} "
502 F"{balance: <{bal_len + 5}} "
503 F"<<{author.display_name}>>\n"
504 )
505
506 fstring = (
507 F"We have to remember to escape {braces}."
508 " Like {these}."
509 F" But not {this}."
510 )
511
512 welcome_to_programming = R"hello," R" world!"
513
514 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."
515
516 x = F"This is a long string which contains an f-expr that should not split {{{[i for i in range(5)]}}}."
517
518 x = (
519 "\N{BLACK RIGHT-POINTING TRIANGLE WITH DOUBLE VERTICAL BAR}\N{VARIATION SELECTOR-16}"
520 )
521
522 xxxxxx_xxx_xxxx_xx_xxxxx_xxxxxxxx_xxxxxxxx_xxxxxxxxxx_xxxx_xxxx_xxxxx = xxxx.xxxxxx.xxxxxxxxx.xxxxxxxxxxxxxxxxxxxx(
523 xx_xxxxxx={
524 "x3_xxxxxxxx": "xxx3_xxxxx_xxxxxxxx_xxxxxxxx_xxxxxxxxxx_xxxxxxxx_xxxxxx_xxxxxxx",
525 },
526 )
527
528 # Regression test for https://github.com/psf/black/issues/3117.
529 some_dict = {
530 "something_something":
531 r"Lorem ipsum dolor sit amet, an sed convenire eloquentiam \t"
532 r"signiferumque, duo ea vocibus consetetur scriptorem. Facer \t",
533 }
534
535 # Regression test for https://github.com/psf/black/issues/3459.
536 xxxx(
537 empty_str_as_first_split=''
538 f'xxxxxxx {xxxxxxxxxx} xxx xxxxxxxxxx xxxxx xxx xxx xx '
539 'xxxxx xxxxxxxxx xxxxxxx, xxx xxxxxxxxxxx xxx xxxxx. '
540 f'xxxxxxxxxxxxx xxxx xx xxxxxxxxxx. xxxxx: {x.xxx}',
541 empty_u_str_as_first_split=u''
542 f'xxxxxxx {xxxxxxxxxx} xxx xxxxxxxxxx xxxxx xxx xxx xx '
543 'xxxxx xxxxxxxxx xxxxxxx, xxx xxxxxxxxxxx xxx xxxxx. '
544 f'xxxxxxxxxxxxx xxxx xx xxxxxxxxxx. xxxxx: {x.xxx}',
545 )
546
547 # Regression test for https://github.com/psf/black/issues/3455.
548 a_dict = {
549 "/this/is/a/very/very/very/very/very/very/very/very/very/very/long/key/without/spaces":
550 # And there is a comment before the value
551 ("item1", "item2", "item3"),
552 }
553
554 # Regression test for https://github.com/psf/black/issues/3506.
555 # Regressed again by https://github.com/psf/black/pull/4498
556 s = (
557 "With single quote: ' "
558 f" {my_dict['foo']}"
559 ' With double quote: " '
560 f' {my_dict["bar"]}'
561 )
562
563 s = f'Lorem Ipsum is simply dummy text of the printing and typesetting industry:\'{my_dict["foo"]}\''
564
565 # Regression test for https://github.com/psf/black/issues/4510.
566 # Don't merge multi-line strings when a pragma comment follows.
567 (
568 "A very very very very very very very very very very very very long string "
569 "annotated with a type ignore pragma gets merged into a single very long line "
570 "which is against the line length rule."
571 ) # type: ignore
572
573
574 # output
575
576
577 class A:
578 def foo():
579 result = type(message)("")
580
581
582 # Don't merge multiline (e.g. triple-quoted) strings.
583 def foo():
584 query = (
585 """SELECT xxxxxxxxxxxxxxxxxxxx(xxx)"""
586 """ FROM xxxxxxxxxxxxxxxx WHERE xxxxxxxxxx AND xxx <> xxxxxxxxxxxxxx()"""
587 )
588
589
590 # There was a bug where tuples were being identified as long strings.
591 long_tuple = (
592 "Apple",
593 "Berry",
594 "Cherry",
595 "Dill",
596 "Evergreen",
597 "Fig",
598 "Grape",
599 "Harry",
600 "Iglu",
601 "Jaguar",
602 )
603
604 stupid_format_method_bug = (
605 "Some really long string that just so happens to be the {} {} to force the 'format'"
606 " method to hang over the line length boundary. This is pretty annoying.".format(
607 "perfect", "length"
608 )
609 )
610
611
612 class A:
613 def foo():
614 os.system(
615 "This is a regression test. xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx"
616 " xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx"
617 " xxxx.".format("xxxxxxxxxx", "xxxxxx", "xxxxxxxxxx")
618 )
619
620
621 class A:
622 def foo():
623 XXXXXXXXXXXX.append((
624 "xxx_xxxxxxxxxx(xxxxx={}, xxxx={}, xxxxx, xxxx_xxxx_xxxxxxxxxx={})".format(
625 xxxxx, xxxx, xxxx_xxxx_xxxxxxxxxx
626 ),
627 my_var,
628 my_other_var,
629 ))
630
631
632 class A:
633 class B:
634 def foo():
635 bar(
636 "[{}]: xxx_xxxxxxxxxx(xxxxx={}, xxxx={}, xxxxx={}"
637 " xxxx_xxxx_xxxxxxxxxx={}, xxxx={})".format(
638 xxxx._xxxxxxxxxxxxxx, xxxxx, xxxx, xxxx_xxxx_xxxxxxxxxx, xxxxxxx
639 ),
640 varX,
641 varY,
642 varZ,
643 )
644
645
646 def foo(xxxx):
647 for xxx_xxxx, _xxx_xxx, _xxx_xxxxx, xxx_xxxx in xxxx:
648 for xxx in xxx_xxxx:
649 assert ("x" in xxx) or (xxx in xxx_xxx_xxxxx), (
650 "{0} xxxxxxx xx {1}, xxx {1} xx xxx xx xxxx xx xxx xxxx: xxx xxxx {2}"
651 .format(xxx_xxxx, xxx, xxxxxx.xxxxxxx(xxx_xxx_xxxxx))
652 )
653
654
655 class A:
656 def disappearing_comment():
657 return (
658 ( # xx -x xxxxxxx xx xxx xxxxxxx.
659 "{{xxx_xxxxxxxxxx_xxxxxxxx}} xxx xxxx {} {{xxxx}} >&2".format(
660 "{xxxx} {xxxxxx}"
661 if xxxxx.xx_xxxxxxxxxx
662 else ( # Disappearing Comment
663 "--xxxxxxx --xxxxxx=x --xxxxxx-xxxxx=xxxxxx"
664 " --xxxxxx-xxxx=xxxxxxxxxxx.xxx"
665 )
666 )
667 ),
668 (x, y, z),
669 )
670
671
672 class A:
673 class B:
674 def foo():
675 xxxxx_xxxx(
676 xx,
677 "\t"
678 "@xxxxxx '{xxxx_xxx}\t' > {xxxxxx_xxxx}.xxxxxxx;"
679 "{xxxx_xxx} >> {xxxxxx_xxxx}.xxxxxxx 2>&1; xx=$$?;"
680 "xxxx $$xx".format(
681 xxxx_xxx=xxxx_xxxxxxx,
682 xxxxxx_xxxx=xxxxxxx + "/" + xxxx_xxx_xxxx,
683 x=xxx_xxxxx_xxxxx_xxx,
684 ),
685 x,
686 y,
687 z,
688 )
689
690
691 func_call_where_string_arg_has_method_call_and_bad_parens(
692 "A long string with {}. This string is so long that it is ridiculous. It can't fit"
693 " on one line at alllll.".format("formatting"),
694 )
695
696 func_call_where_string_arg_has_old_fmt_and_bad_parens(
697 "A long string with {}. This string is so long that it is ridiculous. It can't fit"
698 " on one line at alllll." % "formatting",
699 )
700
701 func_call_where_string_arg_has_old_fmt_and_bad_parens(
702 "A long string with {}. This {} is so long that it is ridiculous. It can't fit on"
703 " one line at alllll." % ("formatting", "string"),
704 )
705
706
707 class A:
708 def append(self):
709 if True:
710 xxxx.xxxxxxx.xxxxx(
711 "xxxxxxxxxx xxxx xx xxxxxx(%x) xx %x xxxx xx xxx %x.xx"
712 % (len(self) + 1, xxxx.xxxxxxxxxx, xxxx.xxxxxxxxxx)
713 + " %.3f (%s) to %.3f (%s).\n"
714 % (
715 xxxx.xxxxxxxxx,
716 xxxx.xxxxxxxxxxxxxx(xxxx.xxxxxxxxx),
717 x,
718 xxxx.xxxxxxxxxxxxxx(xx),
719 )
720 )
721
722
723 class A:
724 def foo():
725 some_func_call(
726 "xxxxxxxxxx",
727 "xx {xxxxxxxxxxx}/xxxxxxxxxxx.xxx xxxx.xxx && xxxxxx -x "
728 '"xxxx xxxxxxx xxxxxx xxxx; xxxx xxxxxx_xxxxx xxxxxx xxxx; '
729 "xxxx.xxxx_xxxxxx(['xxxx.xxx'], xxxx.xxxxxxx().xxxxxxxxxx)\" ",
730 None,
731 ("xxxxxxxxxxx",),
732 ),
733
734
735 class A:
736 def foo():
737 some_func_call(
738 "xx {xxxxxxxxxxx}/xxxxxxxxxxx.xxx xxxx.xxx && xxxxxx -x "
739 "xxxx, ('xxxxxxx xxxxxx xxxx, xxxx') xxxxxx_xxxxx xxxxxx xxxx; "
740 "xxxx.xxxx_xxxxxx(['xxxx.xxx'], xxxx.xxxxxxx().xxxxxxxxxx)\" ",
741 None,
742 ("xxxxxxxxxxx",),
743 ),
744
745
746 xxxxxxx = {
747 "xx": (
748 "xxxx xxxxxxx xxxxxxxxx -x xxx -x /xxx/{0} -x xxx,xxx -xx {1} -xx {1} -xx"
749 " xxx=xxx_xxxx,xxx_xx,xxx_xxx,xxx_xxxx,xxx_xx,xxx_xxx | xxxxxx -x xxxxxxxx -x"
750 " xxxxxxxx -x"
751 ),
752 "xx": (
753 "xxxx xxxxxxx xxxxxxxxx -x xxx -x /xxx/{0} -x xxx,xxx -xx {1} -xx {1} -xx"
754 " xxx=xxx_xxxx_xxx_xxxx,xxx_xx_xxx_xxxx,xxx_xxxx_xxx_xxxx,xxx_xx_xxxx_xxxx,xxx_xxx_xxxx,xxx_xxx_xxxx"
755 " xxxx=xxx | xxxxxx -x xxxxxxxx -x xxxxxxxx -x"
756 ),
757 }
758
759
760 class A:
761 def foo(self):
762 if True:
763 xxxxx_xxxxxxxxxxxx(
764 "xxx xxxxxx xxx xxxxxxxxx.xx xx xxxxxxxx. xxx xxxxxxxxxxxxx.xx"
765 " xxxxxxx "
766 + "xx xxxxxx xxxxxx xxxxxx xx xxxxxxx xxx xxx ${0} xx x xxxxxxxx xxxxx"
767 .xxxxxx(xxxxxx_xxxxxx_xxx)
768 )
769
770
771 class A:
772 class B:
773 def foo():
774 row = {
775 "xxxxxxxxxxxxxxx": xxxxxx_xxxxx_xxxx,
776 # 'xxxxxxxxxxxxxxxxxxxxxxx'
777 # 'xxxxxxxxxxxxxxxxxxxxxx'
778 # 'xxxxxxxxxxxxxxxxxx'
779 # 'xxxxxxxxxxxxxxxxx'
780 "xxxxxxxxxx": xxxxx_xxxxx,
781 }
782
783
784 class A:
785 def xxxx_xxx_xx_xxxxxxxxxx_xxxx_xxxxxxxxx(xxxx):
786 xxxxxxxx = [
787 xxxxxxxxxxxxxxxx(
788 "xxxx",
789 xxxxxxxxxxx={
790 "xxxx": 1.0,
791 },
792 xxxxxx={"xxxxxx 1": xxxxxx(xxxx="xxxxxx 1", xxxxxx=600.0)},
793 xxxxxxxx_xxxxxxx=0.0,
794 ),
795 xxxxxxxxxxxxxxxx(
796 "xxxxxxx",
797 xxxxxxxxxxx={
798 "xxxx": 1.0,
799 },
800 xxxxxx={"xxxxxx 1": xxxxxx(xxxx="xxxxxx 1", xxxxxx=200.0)},
801 xxxxxxxx_xxxxxxx=0.0,
802 ),
803 xxxxxxxxxxxxxxxx(
804 "xxxx",
805 ),
806 ]
807
808
809 some_dictionary = {
810 "xxxxx006": [
811 (
812 "xxx-xxx"
813 " xxxxx3xxxx1xx2xxxxxxxxxxxxxx0xx6xxxxxxxxxx2xxxxxx9xxxxxxxxxx0xxxxx1xxx2x/xx9xx6+x+xxxxxxxxxxxxxx4xxxxxxxxxxxxxxxxxxxxx43xxx2xx2x4x++xxx6xxxxxxxxx+xxxxx/xx9x+xxxxxxxxxxxxxx8x15xxxxxxxxxxxxxxxxx82xx/xxxxxxxxxxxxxx/x5xxxxxxxxxxxxxx6xxxxxx74x4/xxx4x+xxxxxxxxx2xxxxxxxx87xxxxx4xxxxxxxx3xx0xxxxx4xxx1xx9xx5xxxxxxx/xxxxx5xx6xx4xxxx1x/x2xxxxxxxxxxxx64xxxxxxx1x0xx5xxxxxxxxxxxxxx=="
814 " xxxxx000 xxxxxxxxxx\n"
815 ),
816 (
817 "xxx-xxx"
818 " xxxxx3xxxx1xx2xxxxxxxxxxxxxx6xxxxxxxxxxxxxx9xxxxxxxxxxxxx3xxx9xxxxxxxxxxxxxxxx0xxxxxxxxxxxxxxxxx2xxxx2xxx6xxxxx/xx54xxxxxxxxx4xxx3xxxxxx9xx3xxxxx39xxxxxxxxx5xx91xxxx7xxxxxx8xxxxxxxxxxxxxxxx9xxx93xxxxxxxxxxxxxxxxx7xxx8xx8xx4/x1xxxxx1x3xxxxxxxxxxxxx3xxxxxx9xx4xx4x7xxxxxxxxxxxxx1xxxxxxxxx7xxxxxxxxxxxxxx4xx6xxxxxxxxx9xxx7xxxx2xxxxxxxxxxxxxxxxxxxxxx8xxxxxxxxxxxxxxxxxxxx6xx=="
819 " xxxxx010 xxxxxxxxxx\n"
820 ),
821 ],
822 "xxxxx016": [
823 (
824 "xxx-xxx"
825 " xxxxx3xxxx1xx2xxxxxxxxxxxxxx0xx6xxxxxxxxxx2xxxxxx9xxxxxxxxxx0xxxxx1xxx2x/xx9xx6+x+xxxxxxxxxxxxxx4xxxxxxxxxxxxxxxxxxxxx43xxx2xx2x4x++xxx6xxxxxxxxx+xxxxx/xx9x+xxxxxxxxxxxxxx8x15xxxxxxxxxxxxxxxxx82xx/xxxxxxxxxxxxxx/x5xxxxxxxxxxxxxx6xxxxxx74x4/xxx4x+xxxxxxxxx2xxxxxxxx87xxxxx4xxxxxxxx3xx0xxxxx4xxx1xx9xx5xxxxxxx/xxxxx5xx6xx4xxxx1x/x2xxxxxxxxxxxx64xxxxxxx1x0xx5xxxxxxxxxxxxxx=="
826 " xxxxx000 xxxxxxxxxx\n"
827 ),
828 (
829 "xxx-xxx"
830 " xxxxx3xxxx1xx2xxxxxxxxxxxxxx6xxxxxxxxxxxxxx9xxxxxxxxxxxxx3xxx9xxxxxxxxxxxxxxxx0xxxxxxxxxxxxxxxxx2xxxx2xxx6xxxxx/xx54xxxxxxxxx4xxx3xxxxxx9xx3xxxxx39xxxxxxxxx5xx91xxxx7xxxxxx8xxxxxxxxxxxxxxxx9xxx93xxxxxxxxxxxxxxxxx7xxx8xx8xx4/x1xxxxx1x3xxxxxxxxxxxxx3xxxxxx9xx4xx4x7xxxxxxxxxxxxx1xxxxxxxxx7xxxxxxxxxxxxxx4xx6xxxxxxxxx9xxx7xxxx2xxxxxxxxxxxxxxxxxxxxxx8xxxxxxxxxxxxxxxxxxxx6xx=="
831 " xxxxx010 xxxxxxxxxx\n"
832 ),
833 ],
834 }
835
836
837 def foo():
838 xxx_xxx = ( # xxxx xxxxxxxxxx xxxx xx xxxx xx xxx xxxxxxxx xxxxxx xxxxx.
839 'xxxx xxx xxxxxxxx_xxxx xx "xxxxxxxxxx".\n xxx: xxxxxx xxxxxxxx_xxxx=xxxxxxxxxx'
840 )
841
842
843 some_tuple = ("some string", "some string which should be joined")
844
845 some_commented_string = ( # This comment stays at the top.
846 "This string is long but not so long that it needs hahahah toooooo be so greatttt"
847 " {} that I just can't think of any more good words to say about it at"
848 " allllllllllll".format("ha") # comments here are fine
849 )
850
851 some_commented_string = (
852 "This string is long but not so long that it needs hahahah toooooo be so greatttt" # But these
853 " {} that I just can't think of any more good words to say about it at" # comments will stay
854 " allllllllllll".format("ha") # comments here are fine
855 )
856
857 lpar_and_rpar_have_comments = func_call( # LPAR Comment
858 "Long really ridiculous type of string that shouldn't really even exist at all. I"
859 " mean commmme onnn!!!", # Comma Comment
860 ) # RPAR Comment
861
862 cmd_fstring = (
863 "sudo -E deluge-console info --detailed --sort-reverse=time_added "
864 f"{'' if ID is None else ID} | perl -nE 'print if /^{field}:/'"
865 )
866
867 cmd_fstring = (
868 "sudo -E deluge-console info --detailed --sort-reverse=time_added"
869 f" {'' if ID is None else ID} | perl -nE 'print if /^{field}:/'"
870 )
871
872 cmd_fstring = (
873 "sudo -E deluge-console info --detailed --sort-reverse=time_added"
874 f" {'{{}}' if ID is None else ID} | perl -nE 'print if /^{field}:/'"
875 )
876
877 cmd_fstring = (
878 "sudo -E deluge-console info --detailed --sort-reverse=time_added {'' if ID is"
879 f" None else ID}} | perl -nE 'print if /^{field}:/'"
880 )
881
882 fstring = (
883 "This string really doesn't need to be an {{fstring}}, but this one most"
884 f" certainly, absolutely {does}."
885 )
886
887 fstring = f"We have to remember to escape {braces}. Like {{these}}. But not {this}."
888
889
890 class A:
891 class B:
892 def foo():
893 st_error = STError(
894 f"This string ({string_leaf.value}) appears to be pointless (i.e. has"
895 " no parent)."
896 )
897
898
899 def foo():
900 user_regex = _lazy_re_compile(
901 r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*\Z" # dot-atom
902 r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"\Z)', # quoted-string
903 re.IGNORECASE,
904 )
905
906
907 def foo():
908 user_regex = _lazy_re_compile(
909 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # dot-atom
910 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", # quoted-string
911 xyz,
912 )
913
914
915 def foo():
916 user_regex = _lazy_re_compile(
917 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # dot-atom
918 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", # quoted-string
919 xyz,
920 )
921
922
923 class A:
924 class B:
925 def foo():
926 if not hasattr(module, name):
927 raise ValueError(
928 "Could not find object %s in %s.\n"
929 "Please note that you cannot serialize things like inner "
930 "classes. Please move the object into the main module "
931 "body to use migrations.\n"
932 "For more information, see "
933 "https://docs.djangoproject.com/en/%s/topics/migrations/#serializing-values"
934 % (name, module_name, get_docs_version())
935 )
936
937
938 class A:
939 class B:
940 def foo():
941 if not hasattr(module, name):
942 raise ValueError(
943 "Could not find object %s in %s.\nPlease note that you cannot"
944 " serialize things like inner classes. Please move the object into"
945 " the main module body to use migrations.\nFor more information,"
946 " see https://docs.djangoproject.com/en/%s/topics/migrations/#serializing-values"
947 % (name, module_name, get_docs_version())
948 )
949
950
951 x = (
952 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
953 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
954 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
955 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
956 )
957
958
959 class Step(StepBase):
960 def who(self):
961 self.cmd = (
962 "SR AAAA-CORRECT NAME IS {last_name} {first_name}{middle_name}"
963 " {title}/P{passenger_association}".format(
964 last_name=last_name,
965 first_name=first_name,
966 middle_name=middle_name,
967 title=title,
968 passenger_association=passenger_association,
969 )
970 )
971
972
973 xxxxxxx_xxxxxx_xxxxxxx = xxx([
974 xxxxxxxxxxxx(
975 xxxxxx_xxxxxxx=(
976 '((x.aaaaaaaaa = "xxxxxx.xxxxxxxxxxxxxxxxxxxxx") || (x.xxxxxxxxx ='
977 ' "xxxxxxxxxxxx")) && '
978 # xxxxx xxxxxxxxxxxx xxxx xxx (xxxxxxxxxxxxxxxx) xx x xxxxxxxxx xx xxxxxx.
979 "(x.bbbbbbbbbbbb.xxx != "
980 '"xxx:xxx:xxx::cccccccccccc:xxxxxxx-xxxx/xxxxxxxxxxx/xxxxxxxxxxxxxxxxx") && '
981 )
982 )
983 ])
984
985 if __name__ == "__main__":
986 for i in range(4, 8):
987 cmd = (
988 r"for pid in $(ps aux | grep paster | grep -v grep | grep '\-%d' | awk"
989 r" '{print $2}'); do kill $pid; done" % (i)
990 )
991
992
993 def A():
994 def B():
995 def C():
996 def D():
997 def E():
998 def F():
999 def G():
1000 assert (
1001 c_float(val[0][0] / val[0][1]).value
1002 == c_float(value[0][0] / value[0][1]).value
1003 ), "%s didn't roundtrip" % tag
1004
1005
1006 class xxxxxxxxxxxxxxxxxxxxx(xxxx.xxxxxxxxxxxxx):
1007 def xxxxxxx_xxxxxx(xxxx):
1008 assert xxxxxxx_xxxx in [
1009 x.xxxxx.xxxxxx.xxxxx.xxxxxx,
1010 x.xxxxx.xxxxxx.xxxxx.xxxx,
1011 ], (
1012 "xxxxxxxxxxx xxxxxxx xxxx (xxxxxx xxxx) %x xxx xxxxx" % xxxxxxx_xxxx
1013 )
1014
1015
1016 value.__dict__[key] = (
1017 "test" # set some Thrift field to non-None in the struct aa bb cc dd ee
1018 )
1019
1020 RE_ONE_BACKSLASH = {
1021 "asdf_hjkl_jkl": re.compile(
1022 r"(?<!([0-9]\ ))(?<=(^|\ ))([A-Z]+(\ )?|[0-9](\ )|[a-z](\ )){4,7}([A-Z]|[0-9]|[a-z])($|\b)(?!(\ ?([0-9]\ )|(\.)))"
1023 ),
1024 }
1025
1026 RE_TWO_BACKSLASHES = {
1027 "asdf_hjkl_jkl": re.compile(
1028 r"(?<!([0-9]\ ))(?<=(^|\ ))([A-Z]+(\ )?|[0-9](\ )|[a-z](\\"
1029 r" )){4,7}([A-Z]|[0-9]|[a-z])($|\b)(?!(\ ?([0-9]\ )|(\.)))"
1030 ),
1031 }
1032
1033 RE_THREE_BACKSLASHES = {
1034 "asdf_hjkl_jkl": re.compile(
1035 r"(?<!([0-9]\ ))(?<=(^|\ ))([A-Z]+(\ )?|[0-9](\ )|[a-z](\\\ )){4,7}([A-Z]|[0-9]|[a-z])($|\b)(?!(\ ?([0-9]\ )|(\.)))"
1036 ),
1037 }
1038
1039 # We do NOT split on f-string expressions.
1040 print(
1041 "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam."
1042 f" {[f'{i}' for i in range(10)]}"
1043 )
1044 x = (
1045 "This is a long string which contains an f-expr that should not split"
1046 f" {{{[i for i in range(5)]}}}."
1047 )
1048
1049 # The parens should NOT be removed in this case.
1050 (
1051 "my very long string that should get formatted if I'm careful to make sure it goes"
1052 " over 88 characters which it has now"
1053 )
1054
1055 # The parens should NOT be removed in this case.
1056 (
1057 "my very long string that should get formatted if I'm careful to make sure it goes"
1058 " over 88 characters which it has now"
1059 )
1060
1061 # The parens should NOT be removed in this case.
1062 (
1063 "my very long string"
1064 " that should get formatted"
1065 " if I'm careful to make sure"
1066 " it goes over 88 characters which"
1067 " it has now"
1068 )
1069
1070
1071 def _legacy_listen_examples():
1072 text += (
1073 " \"listen for the '%(event_name)s' event\"\n"
1074 "\n # ... (event logic logic logic) ...\n"
1075 % {
1076 "since": since,
1077 }
1078 )
1079
1080
1081 class X:
1082 async def foo(self):
1083 msg = ""
1084 for candidate in CANDIDATES:
1085 msg += (
1086 "**{candidate.object_type} {candidate.rev}**"
1087 " - {candidate.description}\n"
1088 )
1089
1090
1091 temp_msg = (
1092 f"{f'{humanize_number(pos)}.': <{pound_len+2}} "
1093 f"{balance: <{bal_len + 5}} "
1094 f"<<{author.display_name}>>\n"
1095 )
1096
1097 assert (
1098 str(suffix_arr)
1099 == "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', "
1100 "'grykangaroo$', 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', "
1101 "'o$', 'oo$', 'roo$', 'rykangaroo$', 'ykangaroo$']"
1102 )
1103 assert (
1104 str(suffix_arr)
1105 != "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', "
1106 "'grykangaroo$', 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', "
1107 "'o$', 'oo$', 'roo$', 'rykangaroo$', 'ykangaroo$']"
1108 )
1109 assert (
1110 str(suffix_arr)
1111 <= "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', "
1112 "'grykangaroo$', 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', "
1113 "'o$', 'oo$', 'roo$', 'rykangaroo$', 'ykangaroo$']"
1114 )
1115 assert (
1116 str(suffix_arr)
1117 >= "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', "
1118 "'grykangaroo$', 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', "
1119 "'o$', 'oo$', 'roo$', 'rykangaroo$', 'ykangaroo$']"
1120 )
1121 assert (
1122 str(suffix_arr)
1123 < "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', "
1124 "'grykangaroo$', 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', "
1125 "'o$', 'oo$', 'roo$', 'rykangaroo$', 'ykangaroo$']"
1126 )
1127 assert (
1128 str(suffix_arr)
1129 > "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', "
1130 "'grykangaroo$', 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', "
1131 "'o$', 'oo$', 'roo$', 'rykangaroo$', 'ykangaroo$']"
1132 )
1133 assert (
1134 str(suffix_arr)
1135 in "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', 'grykangaroo$',"
1136 " 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', 'o$', 'oo$', 'roo$', 'rykangaroo$',"
1137 " 'ykangaroo$']"
1138 )
1139 assert (
1140 str(suffix_arr)
1141 not in "['$', 'angaroo$', 'angrykangaroo$', 'aroo$', 'garoo$', 'grykangaroo$',"
1142 " 'kangaroo$', 'ngaroo$', 'ngrykangaroo$', 'o$', 'oo$', 'roo$',"
1143 " 'rykangaroo$', 'ykangaroo$']"
1144 )
1145 message = (
1146 f"1. Go to Google Developers Console and log in with your Google account."
1147 f"(https://console.developers.google.com/)"
1148 f"2. You should be prompted to create a new project (name does not matter)."
1149 f"3. Click on Enable APIs and Services at the top."
1150 f"4. In the list of APIs choose or search for YouTube Data API v3 and "
1151 f"click on it. Choose Enable."
1152 f"5. Click on Credentials on the left navigation bar."
1153 f"6. Click on Create Credential at the top."
1154 f'7. At the top click the link for "API key".'
1155 f"8. No application restrictions are needed. Click Create at the bottom."
1156 f"9. You now have a key to add to `{{prefix}}set api youtube api_key`"
1157 )
1158 message = (
1159 f"1. Go to Google Developers Console and log in with your Google account."
1160 f"(https://console.developers.google.com/)"
1161 f"2. You should be prompted to create a new project (name does not matter)."
1162 f"3. Click on Enable APIs and Services at the top."
1163 f"4. In the list of APIs choose or search for YouTube Data API v3 and "
1164 f"click on it. Choose Enable."
1165 f"5. Click on Credentials on the left navigation bar."
1166 f"6. Click on Create Credential at the top."
1167 f'7. At the top click the link for "API key".'
1168 f"8. No application restrictions are needed. Click Create at the bottom."
1169 f"9. You now have a key to add to `{{prefix}}set api youtube api_key`"
1170 )
1171 message = (
1172 "1. Go to Google Developers Console and log in with your Google account."
1173 "(https://console.developers.google.com/)"
1174 "2. You should be prompted to create a new project (name does not matter)."
1175 "3. Click on Enable APIs and Services at the top."
1176 "4. In the list of APIs choose or search for YouTube Data API v3 and "
1177 "click on it. Choose Enable."
1178 "5. Click on Credentials on the left navigation bar."
1179 "6. Click on Create Credential at the top."
1180 '7. At the top click the link for "API key".'
1181 "8. No application restrictions are needed. Click Create at the bottom."
1182 f"9. You now have a key to add to `{prefix}set api youtube api_key`"
1183 )
1184
1185 # It shouldn't matter if the string prefixes are capitalized.
1186 temp_msg = (
1187 f"{F'{humanize_number(pos)}.': <{pound_len+2}} "
1188 f"{balance: <{bal_len + 5}} "
1189 f"<<{author.display_name}>>\n"
1190 )
1191
1192 fstring = f"We have to remember to escape {braces}. Like {{these}}. But not {this}."
1193
1194 welcome_to_programming = R"hello," R" world!"
1195
1196 fstring = (
1197 f"f-strings definitely make things more {difficult} than they need to be for"
1198 " {black}. But boy they sure are handy. The problem is that some lines will need"
1199 f" to have the 'f' whereas others do not. This {line}, for example, needs one."
1200 )
1201
1202 x = (
1203 "This is a long string which contains an f-expr that should not split"
1204 f" {{{[i for i in range(5)]}}}."
1205 )
1206
1207 x = (
1208 "\N{BLACK RIGHT-POINTING TRIANGLE WITH DOUBLE VERTICAL BAR}\N{VARIATION SELECTOR-16}"
1209 )
1210
1211 xxxxxx_xxx_xxxx_xx_xxxxx_xxxxxxxx_xxxxxxxx_xxxxxxxxxx_xxxx_xxxx_xxxxx = xxxx.xxxxxx.xxxxxxxxx.xxxxxxxxxxxxxxxxxxxx(
1212 xx_xxxxxx={
1213 "x3_xxxxxxxx": (
1214 "xxx3_xxxxx_xxxxxxxx_xxxxxxxx_xxxxxxxxxx_xxxxxxxx_xxxxxx_xxxxxxx"
1215 ),
1216 },
1217 )
1218
1219 # Regression test for https://github.com/psf/black/issues/3117.
1220 some_dict = {
1221 "something_something": (
1222 r"Lorem ipsum dolor sit amet, an sed convenire eloquentiam \t"
1223 r"signiferumque, duo ea vocibus consetetur scriptorem. Facer \t"
1224 ),
1225 }
1226
1227 # Regression test for https://github.com/psf/black/issues/3459.
1228 xxxx(
1229 empty_str_as_first_split=(
1230 ""
1231 f"xxxxxxx {xxxxxxxxxx} xxx xxxxxxxxxx xxxxx xxx xxx xx "
1232 "xxxxx xxxxxxxxx xxxxxxx, xxx xxxxxxxxxxx xxx xxxxx. "
1233 f"xxxxxxxxxxxxx xxxx xx xxxxxxxxxx. xxxxx: {x.xxx}"
1234 ),
1235 empty_u_str_as_first_split=(
1236 ""
1237 f"xxxxxxx {xxxxxxxxxx} xxx xxxxxxxxxx xxxxx xxx xxx xx "
1238 "xxxxx xxxxxxxxx xxxxxxx, xxx xxxxxxxxxxx xxx xxxxx. "
1239 f"xxxxxxxxxxxxx xxxx xx xxxxxxxxxx. xxxxx: {x.xxx}"
1240 ),
1241 )
1242
1243 # Regression test for https://github.com/psf/black/issues/3455.
1244 a_dict = {
1245 "/this/is/a/very/very/very/very/very/very/very/very/very/very/long/key/without/spaces":
1246 # And there is a comment before the value
1247 ("item1", "item2", "item3"),
1248 }
1249
1250 # Regression test for https://github.com/psf/black/issues/3506.
1251 # Regressed again by https://github.com/psf/black/pull/4498
1252 s = (
1253 "With single quote: ' "
1254 f" {my_dict['foo']}"
1255 ' With double quote: " '
1256 f' {my_dict["bar"]}'
1257 )
1258
1259 s = (
1260 "Lorem Ipsum is simply dummy text of the printing and typesetting"
1261 f' industry:\'{my_dict["foo"]}\''
1262 )
1263
1264 # Regression test for https://github.com/psf/black/issues/4510.
1265 # Don't merge multi-line strings when a pragma comment follows.
1266 (
1267 "A very very very very very very very very very very very very long string "
1268 "annotated with a type ignore pragma gets merged into a single very long line "
1269 "which is against the line length rule."
1270 ) # type: ignore