]> 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:

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