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

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