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

Format subscriptions in a PEP-8 compliant way (#178)
[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 for x, in (1,), (2,), (3,): ...
167 for y in (): ...
168 for z in (i for i in (1, 2, 3)): ...
169 for i in (call()): ...
170 for j in (1 + (2 + 3)): ...
171 while(this and that): ...
172 if (
173     threading.current_thread() != threading.main_thread() and
174     threading.current_thread() != threading.main_thread() or
175     signal.getsignal(signal.SIGINT) != signal.default_int_handler
176 ):
177     return True
178 if (
179     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
180     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
181 ):
182     return True
183 if (
184     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &
185     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
186 ):
187     return True
188 if (
189     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
190     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
191 ):
192     return True
193 if (
194     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -
195     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
196 ):
197     return True
198 if (
199     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *
200     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
201 ):
202     return True
203 if (
204     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa /
205     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
206 ):
207     return True
208 last_call()
209 # standalone comment at ENDMARKER
210
211
212 # output
213
214
215 ...
216 "some_string"
217 b"\\xa3"
218 Name
219 None
220 True
221 False
222 1
223 1.0
224 1j
225 True or False
226 True or False or None
227 True and False
228 True and False and None
229 (Name1 and Name2) or Name3
230 Name1 and Name2 or Name3
231 Name1 or (Name2 and Name3)
232 Name1 or Name2 and Name3
233 (Name1 and Name2) or (Name3 and Name4)
234 Name1 and Name2 or Name3 and Name4
235 Name1 or (Name2 and Name3) or Name4
236 Name1 or Name2 and Name3 or Name4
237 v1 << 2
238 1 >> v2
239 1 % finished
240 1 + v2 - v3 * 4 ^ 5 ** v6 / 7 // 8
241 ((1 + v2) - (v3 * 4)) ^ (((5 ** v6) / 7) // 8)
242 not great
243 ~great
244 +value
245 -1
246 ~int and not v1 ^ 123 + v2 | True
247 (~int) and (not ((v1 ^ (123 + v2)) | True))
248 flags & ~select.EPOLLIN and waiters.write_task is not None
249 lambda arg: None
250 lambda a=True: a
251 lambda a, b, c=True: a
252 lambda a, b, c=True, *, d=(1 << v2), e="str": a
253 lambda a, b, c=True, *vararg, d=(v1 << 2), e="str", **kwargs: a + b
254 foo = (
255     lambda port_id, ignore_missing: {"port1": port1_resource, "port2": port2_resource}[
256         port_id
257     ]
258 )
259 1 if True else 2
260 str or None if True else str or bytes or None
261 (str or None) if True else (str or bytes or None)
262 str or None if (1 if True else 2) else str or bytes or None
263 (str or None) if (1 if True else 2) else (str or bytes or None)
264 (
265     (super_long_variable_name or None)
266     if (1 if super_long_test_name else 2)
267     else (str or bytes or None)
268 )
269 {"2.7": dead, "3.7": (long_live or die_hard)}
270 {"2.7": dead, "3.7": (long_live or die_hard), **{"3.6": verygood}}
271 {**a, **b, **c}
272 {"2.7", "3.6", "3.7", "3.8", "3.9", ("4.0" if gilectomy else "3.10")}
273 ({"a": "b"}, (True or False), (+value), "string", b"bytes") or None
274 ()
275 (1,)
276 (1, 2)
277 (1, 2, 3)
278 []
279 [1, 2, 3, 4, 5, 6, 7, 8, 9, (10 or A), (11 or B), (12 or C)]
280 [1, 2, 3]
281 [*a]
282 [*range(10)]
283 [*a, 4, 5]
284 [4, *a, 5]
285 [
286     this_is_a_very_long_variable_which_will_force_a_delimiter_split,
287     element,
288     another,
289     *more,
290 ]
291 {i for i in (1, 2, 3)}
292 {(i ** 2) for i in (1, 2, 3)}
293 {(i ** 2) for i, _ in ((1, "a"), (2, "b"), (3, "c"))}
294 {((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3)}
295 [i for i in (1, 2, 3)]
296 [(i ** 2) for i in (1, 2, 3)]
297 [(i ** 2) for i, _ in ((1, "a"), (2, "b"), (3, "c"))]
298 [((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3)]
299 {i: 0 for i in (1, 2, 3)}
300 {i: j for i, j in ((1, "a"), (2, "b"), (3, "c"))}
301 {a: b * 2 for a, b in dictionary.items()}
302 {a: b * -2 for a, b in dictionary.items()}
303 {
304     k: v
305     for k, v in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension
306 }
307 Python3 > Python2 > COBOL
308 Life is Life
309 call()
310 call(arg)
311 call(kwarg="hey")
312 call(arg, kwarg="hey")
313 call(arg, another, kwarg="hey", **kwargs)
314 call(
315     this_is_a_very_long_variable_which_will_force_a_delimiter_split,
316     arg,
317     another,
318     kwarg="hey",
319     **kwargs
320 )  # note: no trailing comma pre-3.6
321 call(*gidgets[:2])
322 call(a, *gidgets[:2])
323 call(**self.screen_kwargs)
324 call(b, **self.screen_kwargs)
325 lukasz.langa.pl
326 call.me(maybe)
327 1 .real
328 1.0 .real
329 ....__class__
330 list[str]
331 dict[str, int]
332 tuple[str, ...]
333 tuple[str, int, float, dict[str, int]]
334 very_long_variable_name_filters: t.List[
335     t.Tuple[str, t.Union[str, t.List[t.Optional[str]]]],
336 ]
337 slice[0]
338 slice[0:1]
339 slice[0:1:2]
340 slice[:]
341 slice[:-1]
342 slice[1:]
343 slice[::-1]
344 slice[d :: d + 1]
345 slice[:c, c - 1]
346 numpy[:, 0:1]
347 numpy[:, :-1]
348 numpy[0, :]
349 numpy[:, i]
350 numpy[0, :2]
351 numpy[:N, 0]
352 numpy[:2, :4]
353 numpy[2:4, 1:5]
354 numpy[4:, 2:]
355 numpy[:, (0, 1, 2, 5)]
356 numpy[0, [0]]
357 numpy[:, [i]]
358 numpy[1 : c + 1, c]
359 numpy[-(c + 1) :, d]
360 numpy[:, l[-2]]
361 numpy[:, ::-1]
362 numpy[np.newaxis, :]
363 (str or None) if (sys.version_info[0] > (3,)) else (str or bytes or None)
364 {"2.7": dead, "3.7": long_live or die_hard}
365 {"2.7", "3.6", "3.7", "3.8", "3.9", "4.0" if gilectomy else "3.10"}
366 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10 or A, 11 or B, 12 or C]
367 (SomeName)
368 SomeName
369 (Good, Bad, Ugly)
370 (i for i in (1, 2, 3))
371 ((i ** 2) for i in (1, 2, 3))
372 ((i ** 2) for i, _ in ((1, "a"), (2, "b"), (3, "c")))
373 (((i ** 2) + j) for i in (1, 2, 3) for j in (1, 2, 3))
374 (*starred)
375 {
376     "id": "1",
377     "type": "type",
378     "started_at": now(),
379     "ended_at": now() + timedelta(days=10),
380     "priority": 1,
381     "import_session_id": 1,
382     **kwargs,
383 }
384 a = (1,)
385 b = 1,
386 c = 1
387 d = (1,) + a + (2,)
388 e = (1,).count(1)
389 what_is_up_with_those_new_coord_names = (coord_names + set(vars_to_create)) + set(
390     vars_to_remove
391 )
392 what_is_up_with_those_new_coord_names = (coord_names | set(vars_to_create)) - set(
393     vars_to_remove
394 )
395 result = session.query(models.Customer.id).filter(
396     models.Customer.account_id == account_id, models.Customer.email == email_address
397 ).order_by(
398     models.Customer.id.asc()
399 ).all()
400 Ø = set()
401 authors.łukasz.say_thanks()
402 mapping = {
403     A: 0.25 * (10.0 / 12),
404     B: 0.1 * (10.0 / 12),
405     C: 0.1 * (10.0 / 12),
406     D: 0.1 * (10.0 / 12),
407 }
408
409
410 def gen():
411     yield from outside_of_generator
412     a = (yield)
413
414
415 async def f():
416     await some.complicated[0].call(with_args=(True or (1 is not 1)))
417
418
419 print(*[] or [1])
420 print(**{1: 3} if False else {x: x for x in range(3)})
421 print(*lambda x: x)
422 for (x,) in (1,), (2,), (3,):
423     ...
424 for y in ():
425     ...
426 for z in (i for i in (1, 2, 3)):
427     ...
428 for i in call():
429     ...
430 for j in 1 + (2 + 3):
431     ...
432 while this and that:
433     ...
434 if (
435     threading.current_thread() != threading.main_thread()
436     and threading.current_thread() != threading.main_thread()
437     or signal.getsignal(signal.SIGINT) != signal.default_int_handler
438 ):
439     return True
440 if (
441     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
442     | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
443 ):
444     return True
445 if (
446     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
447     & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
448 ):
449     return True
450 if (
451     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
452     + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
453 ):
454     return True
455 if (
456     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
457     - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
458 ):
459     return True
460 if (
461     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
462     * aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
463 ):
464     return True
465 if (
466     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
467     / aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
468 ):
469     return True
470 last_call()
471 # standalone comment at ENDMARKER