]> git.madduck.net Git - etc/vim.git/blob - tests/expression.py

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Don't make parentheses invisible around yield expressions
[etc/vim.git] / tests / expression.py
1 ...
2 'some_string'
3 b'\\xa3'
4 Name
5 None
6 True
7 False
8 1
9 1.0
10 1j
11 True or False
12 True or False or None
13 True and False
14 True and False and None
15 (Name1 and Name2) or Name3
16 Name1 and Name2 or Name3
17 Name1 or (Name2 and Name3)
18 Name1 or Name2 and Name3
19 (Name1 and Name2) or (Name3 and Name4)
20 Name1 and Name2 or Name3 and Name4
21 Name1 or (Name2 and Name3) or Name4
22 Name1 or Name2 and Name3 or Name4
23 v1 << 2
24 1 >> v2
25 1 % finished
26 1 + v2 - v3 * 4 ^ 5 ** v6 / 7 // 8
27 ((1 + v2) - (v3 * 4)) ^ (((5 ** v6) / 7) // 8)
28 not great
29 ~great
30 +value
31 -1
32 ~int and not v1 ^ 123 + v2 | True
33 (~int) and (not ((v1 ^ (123 + v2)) | True))
34 flags & ~ select.EPOLLIN and waiters.write_task is not None
35 lambda arg: None
36 lambda a=True: a
37 lambda a, b, c=True: a
38 lambda a, b, c=True, *, d=(1 << v2), e='str': a
39 lambda a, b, c=True, *vararg, d=(v1 << 2), e='str', **kwargs: a + b
40 manylambdas = lambda x=lambda y=lambda z=1: z: y(): x()
41 foo = (lambda port_id, ignore_missing: {"port1": port1_resource, "port2": port2_resource}[port_id])
42 1 if True else 2
43 str or None if True else str or bytes or None
44 (str or None) if True else (str or bytes or None)
45 str or None if (1 if True else 2) else str or bytes or None
46 (str or None) if (1 if True else 2) else (str or bytes or None)
47 ((super_long_variable_name or None) if (1 if super_long_test_name else 2) else (str or bytes or None))
48 {'2.7': dead, '3.7': (long_live or die_hard)}
49 {'2.7': dead, '3.7': (long_live or die_hard), **{'3.6': verygood}}
50 {**a, **b, **c}
51 {'2.7', '3.6', '3.7', '3.8', '3.9', ('4.0' if gilectomy else '3.10')}
52 ({'a': 'b'}, (True or False), (+value), 'string', b'bytes') or None
53 ()
54 (1,)
55 (1, 2)
56 (1, 2, 3)
57 []
58 [1, 2, 3, 4, 5, 6, 7, 8, 9, (10 or A), (11 or B), (12 or C)]
59 [1, 2, 3,]
60 [*a]
61 [*range(10)]
62 [*a, 4, 5,]
63 [4, *a, 5,]
64 [this_is_a_very_long_variable_which_will_force_a_delimiter_split, element, another, *more]
65 {i for i in (1, 2, 3)}
66 {(i ** 2) for i in (1, 2, 3)}
67 {(i ** 2) for i, _ in ((1, 'a'), (2, 'b'), (3, 'c'))}
68 {((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3)}
69 [i for i in (1, 2, 3)]
70 [(i ** 2) for i in (1, 2, 3)]
71 [(i ** 2) for i, _ in ((1, 'a'), (2, 'b'), (3, 'c'))]
72 [((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3)]
73 {i: 0 for i in (1, 2, 3)}
74 {i: j for i, j in ((1, 'a'), (2, 'b'), (3, 'c'))}
75 {a: b * 2 for a, b in dictionary.items()}
76 {a: b * -2 for a, b in dictionary.items()}
77 {k: v for k, v in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension}
78 Python3 > Python2 > COBOL
79 Life is Life
80 call()
81 call(arg)
82 call(kwarg='hey')
83 call(arg, kwarg='hey')
84 call(arg, another, kwarg='hey', **kwargs)
85 call(this_is_a_very_long_variable_which_will_force_a_delimiter_split, arg, another, kwarg='hey', **kwargs)  # note: no trailing comma pre-3.6
86 call(*gidgets[:2])
87 call(a, *gidgets[:2])
88 call(**self.screen_kwargs)
89 call(b, **self.screen_kwargs)
90 lukasz.langa.pl
91 call.me(maybe)
92 1 .real
93 1.0 .real
94 ....__class__
95 list[str]
96 dict[str, int]
97 tuple[str, ...]
98 tuple[str, int, float, dict[str, int],]
99 very_long_variable_name_filters: t.List[
100     t.Tuple[str, t.Union[str, t.List[t.Optional[str]]]],
101 ]
102 slice[0]
103 slice[0:1]
104 slice[0:1:2]
105 slice[:]
106 slice[:-1]
107 slice[1:]
108 slice[::-1]
109 slice[d :: d + 1]
110 slice[:c, c - 1]
111 numpy[:, 0:1]
112 numpy[:, :-1]
113 numpy[0, :]
114 numpy[:, i]
115 numpy[0, :2]
116 numpy[:N, 0]
117 numpy[:2, :4]
118 numpy[2:4, 1:5]
119 numpy[4:, 2:]
120 numpy[:, (0, 1, 2, 5)]
121 numpy[0, [0]]
122 numpy[:, [i]]
123 numpy[1 : c + 1, c]
124 numpy[-(c + 1) :, d]
125 numpy[:, l[-2]]
126 numpy[:, ::-1]
127 numpy[np.newaxis, :]
128 (str or None) if (sys.version_info[0] > (3,)) else (str or bytes or None)
129 {'2.7': dead, '3.7': long_live or die_hard}
130 {'2.7', '3.6', '3.7', '3.8', '3.9', '4.0' if gilectomy else '3.10'}
131 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10 or A, 11 or B, 12 or C]
132 (SomeName)
133 SomeName
134 (Good, Bad, Ugly)
135 (i for i in (1, 2, 3))
136 ((i ** 2) for i in (1, 2, 3))
137 ((i ** 2) for i, _ in ((1, 'a'), (2, 'b'), (3, 'c')))
138 (((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3))
139 (*starred)
140 {"id": "1","type": "type","started_at": now(),"ended_at": now() + timedelta(days=10),"priority": 1,"import_session_id": 1,**kwargs}
141 a = (1,)
142 b = 1,
143 c = 1
144 d = (1,) + a + (2,)
145 e = (1,).count(1)
146 what_is_up_with_those_new_coord_names = (coord_names + set(vars_to_create)) + set(vars_to_remove)
147 what_is_up_with_those_new_coord_names = (coord_names | set(vars_to_create)) - set(vars_to_remove)
148 result = session.query(models.Customer.id).filter(models.Customer.account_id == account_id, models.Customer.email == email_address).order_by(models.Customer.id.asc(),).all()
149 Ø = set()
150 authors.łukasz.say_thanks()
151 mapping = {
152     A: 0.25 * (10.0 / 12),
153     B: 0.1 * (10.0 / 12),
154     C: 0.1 * (10.0 / 12),
155     D: 0.1 * (10.0 / 12),
156 }
157
158 def gen():
159     yield from outside_of_generator
160     a = (yield)
161
162 async def f():
163     await some.complicated[0].call(with_args=(True or (1 is not 1)))
164 print(* [] or [1])
165 print(**{1: 3} if False else {x: x for x in range(3)})
166 print(* lambda x: x)
167 assert(not Test),("Short message")
168 assert this is ComplexTest and not requirements.fit_in_a_single_line(force=False), "Short message"
169 assert(((parens is TooMany)))
170 for x, in (1,), (2,), (3,): ...
171 for y in (): ...
172 for z in (i for i in (1, 2, 3)): ...
173 for i in (call()): ...
174 for j in (1 + (2 + 3)): ...
175 while(this and that): ...
176 if (
177     threading.current_thread() != threading.main_thread() and
178     threading.current_thread() != threading.main_thread() or
179     signal.getsignal(signal.SIGINT) != signal.default_int_handler
180 ):
181     return True
182 if (
183     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
184     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
185 ):
186     return True
187 if (
188     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &
189     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
190 ):
191     return True
192 if (
193     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
194     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
195 ):
196     return True
197 if (
198     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -
199     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
200 ):
201     return True
202 if (
203     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *
204     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
205 ):
206     return True
207 if (
208     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa /
209     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
210 ):
211     return True
212 if (
213     ~ aaaa.a + aaaa.b - aaaa.c * aaaa.d / aaaa.e | aaaa.f & aaaa.g % aaaa.h ^ aaaa.i << aaaa.k >> aaaa.l ** aaaa.m // aaaa.n
214 ):
215     return True
216 if (
217     ~ aaaaaaaa.a + aaaaaaaa.b - aaaaaaaa.c @ aaaaaaaa.d / aaaaaaaa.e | aaaaaaaa.f & aaaaaaaa.g % aaaaaaaa.h ^ aaaaaaaa.i << aaaaaaaa.k >> aaaaaaaa.l ** aaaaaaaa.m // aaaaaaaa.n
218 ):
219     return True
220 if (
221     ~ aaaaaaaaaaaaaaaa.a + aaaaaaaaaaaaaaaa.b - aaaaaaaaaaaaaaaa.c * aaaaaaaaaaaaaaaa.d @ aaaaaaaaaaaaaaaa.e | aaaaaaaaaaaaaaaa.f & aaaaaaaaaaaaaaaa.g % aaaaaaaaaaaaaaaa.h ^ aaaaaaaaaaaaaaaa.i << aaaaaaaaaaaaaaaa.k >> aaaaaaaaaaaaaaaa.l ** aaaaaaaaaaaaaaaa.m // aaaaaaaaaaaaaaaa.n
222 ):
223     return True
224 last_call()
225 # standalone comment at ENDMARKER
226
227
228 # output
229
230
231 ...
232 "some_string"
233 b"\\xa3"
234 Name
235 None
236 True
237 False
238 1
239 1.0
240 1j
241 True or False
242 True or False or None
243 True and False
244 True and False and None
245 (Name1 and Name2) or Name3
246 Name1 and Name2 or Name3
247 Name1 or (Name2 and Name3)
248 Name1 or Name2 and Name3
249 (Name1 and Name2) or (Name3 and Name4)
250 Name1 and Name2 or Name3 and Name4
251 Name1 or (Name2 and Name3) or Name4
252 Name1 or Name2 and Name3 or Name4
253 v1 << 2
254 1 >> v2
255 1 % finished
256 1 + v2 - v3 * 4 ^ 5 ** v6 / 7 // 8
257 ((1 + v2) - (v3 * 4)) ^ (((5 ** v6) / 7) // 8)
258 not great
259 ~great
260 +value
261 -1
262 ~int and not v1 ^ 123 + v2 | True
263 (~int) and (not ((v1 ^ (123 + v2)) | True))
264 flags & ~select.EPOLLIN and waiters.write_task is not None
265 lambda arg: None
266 lambda a=True: a
267 lambda a, b, c=True: a
268 lambda a, b, c=True, *, d=(1 << v2), e="str": a
269 lambda a, b, c=True, *vararg, d=(v1 << 2), e="str", **kwargs: a + b
270 manylambdas = lambda x=lambda y=lambda z=1: z: y(): x()
271 foo = lambda port_id, ignore_missing: {
272     "port1": port1_resource, "port2": port2_resource
273 }[
274     port_id
275 ]
276 1 if True else 2
277 str or None if True else str or bytes or None
278 (str or None) if True else (str or bytes or None)
279 str or None if (1 if True else 2) else str or bytes or None
280 (str or None) if (1 if True else 2) else (str or bytes or None)
281 (
282     (super_long_variable_name or None)
283     if (1 if super_long_test_name else 2)
284     else (str or bytes or None)
285 )
286 {"2.7": dead, "3.7": (long_live or die_hard)}
287 {"2.7": dead, "3.7": (long_live or die_hard), **{"3.6": verygood}}
288 {**a, **b, **c}
289 {"2.7", "3.6", "3.7", "3.8", "3.9", ("4.0" if gilectomy else "3.10")}
290 ({"a": "b"}, (True or False), (+value), "string", b"bytes") or None
291 ()
292 (1,)
293 (1, 2)
294 (1, 2, 3)
295 []
296 [1, 2, 3, 4, 5, 6, 7, 8, 9, (10 or A), (11 or B), (12 or C)]
297 [1, 2, 3]
298 [*a]
299 [*range(10)]
300 [*a, 4, 5]
301 [4, *a, 5]
302 [
303     this_is_a_very_long_variable_which_will_force_a_delimiter_split,
304     element,
305     another,
306     *more,
307 ]
308 {i for i in (1, 2, 3)}
309 {(i ** 2) for i in (1, 2, 3)}
310 {(i ** 2) for i, _ in ((1, "a"), (2, "b"), (3, "c"))}
311 {((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3)}
312 [i for i in (1, 2, 3)]
313 [(i ** 2) for i in (1, 2, 3)]
314 [(i ** 2) for i, _ in ((1, "a"), (2, "b"), (3, "c"))]
315 [((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3)]
316 {i: 0 for i in (1, 2, 3)}
317 {i: j for i, j in ((1, "a"), (2, "b"), (3, "c"))}
318 {a: b * 2 for a, b in dictionary.items()}
319 {a: b * -2 for a, b in dictionary.items()}
320 {
321     k: v
322     for k, v in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension
323 }
324 Python3 > Python2 > COBOL
325 Life is Life
326 call()
327 call(arg)
328 call(kwarg="hey")
329 call(arg, kwarg="hey")
330 call(arg, another, kwarg="hey", **kwargs)
331 call(
332     this_is_a_very_long_variable_which_will_force_a_delimiter_split,
333     arg,
334     another,
335     kwarg="hey",
336     **kwargs
337 )  # note: no trailing comma pre-3.6
338 call(*gidgets[:2])
339 call(a, *gidgets[:2])
340 call(**self.screen_kwargs)
341 call(b, **self.screen_kwargs)
342 lukasz.langa.pl
343 call.me(maybe)
344 1 .real
345 1.0 .real
346 ....__class__
347 list[str]
348 dict[str, int]
349 tuple[str, ...]
350 tuple[str, int, float, dict[str, int]]
351 very_long_variable_name_filters: t.List[
352     t.Tuple[str, t.Union[str, t.List[t.Optional[str]]]],
353 ]
354 slice[0]
355 slice[0:1]
356 slice[0:1:2]
357 slice[:]
358 slice[:-1]
359 slice[1:]
360 slice[::-1]
361 slice[d :: d + 1]
362 slice[:c, c - 1]
363 numpy[:, 0:1]
364 numpy[:, :-1]
365 numpy[0, :]
366 numpy[:, i]
367 numpy[0, :2]
368 numpy[:N, 0]
369 numpy[:2, :4]
370 numpy[2:4, 1:5]
371 numpy[4:, 2:]
372 numpy[:, (0, 1, 2, 5)]
373 numpy[0, [0]]
374 numpy[:, [i]]
375 numpy[1 : c + 1, c]
376 numpy[-(c + 1) :, d]
377 numpy[:, l[-2]]
378 numpy[:, ::-1]
379 numpy[np.newaxis, :]
380 (str or None) if (sys.version_info[0] > (3,)) else (str or bytes or None)
381 {"2.7": dead, "3.7": long_live or die_hard}
382 {"2.7", "3.6", "3.7", "3.8", "3.9", "4.0" if gilectomy else "3.10"}
383 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10 or A, 11 or B, 12 or C]
384 (SomeName)
385 SomeName
386 (Good, Bad, Ugly)
387 (i for i in (1, 2, 3))
388 ((i ** 2) for i in (1, 2, 3))
389 ((i ** 2) for i, _ in ((1, "a"), (2, "b"), (3, "c")))
390 (((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3))
391 (*starred)
392 {
393     "id": "1",
394     "type": "type",
395     "started_at": now(),
396     "ended_at": now() + timedelta(days=10),
397     "priority": 1,
398     "import_session_id": 1,
399     **kwargs,
400 }
401 a = (1,)
402 b = (1,)
403 c = 1
404 d = (1,) + a + (2,)
405 e = (1,).count(1)
406 what_is_up_with_those_new_coord_names = (
407     (coord_names + set(vars_to_create)) + set(vars_to_remove)
408 )
409 what_is_up_with_those_new_coord_names = (
410     (coord_names | set(vars_to_create)) - set(vars_to_remove)
411 )
412 result = session.query(models.Customer.id).filter(
413     models.Customer.account_id == account_id, models.Customer.email == email_address
414 ).order_by(
415     models.Customer.id.asc()
416 ).all()
417 Ø = set()
418 authors.łukasz.say_thanks()
419 mapping = {
420     A: 0.25 * (10.0 / 12),
421     B: 0.1 * (10.0 / 12),
422     C: 0.1 * (10.0 / 12),
423     D: 0.1 * (10.0 / 12),
424 }
425
426
427 def gen():
428     yield from outside_of_generator
429     a = (yield)
430
431
432 async def f():
433     await some.complicated[0].call(with_args=(True or (1 is not 1)))
434
435
436 print(*[] or [1])
437 print(**{1: 3} if False else {x: x for x in range(3)})
438 print(*lambda x: x)
439 assert not Test, "Short message"
440 assert (
441     this is ComplexTest and not requirements.fit_in_a_single_line(force=False)
442 ), "Short message"
443 assert parens is TooMany
444 for (x,) in (1,), (2,), (3,):
445     ...
446 for y in ():
447     ...
448 for z in (i for i in (1, 2, 3)):
449     ...
450 for i in call():
451     ...
452 for j in 1 + (2 + 3):
453     ...
454 while this and that:
455     ...
456 if (
457     threading.current_thread() != threading.main_thread()
458     and threading.current_thread() != threading.main_thread()
459     or signal.getsignal(signal.SIGINT) != signal.default_int_handler
460 ):
461     return True
462 if (
463     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
464     | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
465 ):
466     return True
467 if (
468     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
469     & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
470 ):
471     return True
472 if (
473     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
474     + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
475 ):
476     return True
477 if (
478     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
479     - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
480 ):
481     return True
482 if (
483     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
484     * aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
485 ):
486     return True
487 if (
488     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
489     / aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
490 ):
491     return True
492 if (
493     ~aaaa.a + aaaa.b - aaaa.c * aaaa.d / aaaa.e
494     | aaaa.f & aaaa.g % aaaa.h ^ aaaa.i << aaaa.k >> aaaa.l ** aaaa.m // aaaa.n
495 ):
496     return True
497 if (
498     ~aaaaaaaa.a + aaaaaaaa.b - aaaaaaaa.c @ aaaaaaaa.d / aaaaaaaa.e
499     | aaaaaaaa.f & aaaaaaaa.g % aaaaaaaa.h
500     ^ aaaaaaaa.i << aaaaaaaa.k >> aaaaaaaa.l ** aaaaaaaa.m // aaaaaaaa.n
501 ):
502     return True
503 if (
504     ~aaaaaaaaaaaaaaaa.a
505     + aaaaaaaaaaaaaaaa.b
506     - aaaaaaaaaaaaaaaa.c * aaaaaaaaaaaaaaaa.d @ aaaaaaaaaaaaaaaa.e
507     | aaaaaaaaaaaaaaaa.f & aaaaaaaaaaaaaaaa.g % aaaaaaaaaaaaaaaa.h
508     ^ aaaaaaaaaaaaaaaa.i
509     << aaaaaaaaaaaaaaaa.k
510     >> aaaaaaaaaaaaaaaa.l ** aaaaaaaaaaaaaaaa.m // aaaaaaaaaaaaaaaa.n
511 ):
512     return True
513 last_call()
514 # standalone comment at ENDMARKER