]> git.madduck.net Git - etc/vim.git/blob - tests/data/simple_cases/fmtonoff.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 typos in comments: assignement -> assignment (#3556)
[etc/vim.git] / tests / data / simple_cases / fmtonoff.py
1 #!/usr/bin/env python3
2 import asyncio
3 import sys
4
5 from third_party import X, Y, Z
6
7 from library import some_connection, \
8                     some_decorator
9 # fmt: off
10 from third_party import (X,
11                          Y, Z)
12 # fmt: on
13 f'trigger 3.6 mode'
14 # Comment 1
15
16 # Comment 2
17
18 # fmt: off
19 def func_no_args():
20   a; b; c
21   if True: raise RuntimeError
22   if False: ...
23   for i in range(10):
24     print(i)
25     continue
26   exec('new-style exec', {}, {})
27   return None
28 async def coroutine(arg, exec=False):
29  'Single-line docstring. Multiline is harder to reformat.'
30  async with some_connection() as conn:
31      await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2)
32  await asyncio.sleep(1)
33 @asyncio.coroutine
34 @some_decorator(
35 with_args=True,
36 many_args=[1,2,3]
37 )
38 def function_signature_stress_test(number:int,no_annotation=None,text:str='default',* ,debug:bool=False,**kwargs) -> str:
39  return text[number:-1]
40 # fmt: on
41 def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r''):
42  offset = attr.ib(default=attr.Factory( lambda: _r.uniform(1, 2)))
43  assert task._cancel_stack[:len(old_stack)] == old_stack
44 def spaces_types(a: int = 1, b: tuple = (), c: list = [], d: dict = {}, e: bool = True, f: int = -1, g: int = 1 if False else 2, h: str = "", i: str = r''): ...
45 def spaces2(result= _core.Value(None)):
46  ...
47 something = {
48     # fmt: off
49     key: 'value',
50 }
51
52 def subscriptlist():
53     atom[
54         # fmt: off
55         'some big and',
56         'complex subscript',
57         # fmt: on
58         goes + here, andhere,
59        ]
60
61 def import_as_names():
62     # fmt: off
63     from hello import a,        b
64     'unformatted'
65     # fmt: on
66
67 def testlist_star_expr():
68     # fmt: off
69     a , b = *hello
70     'unformatted'
71     # fmt: on
72
73 def yield_expr():
74     # fmt: off
75     yield hello
76     'unformatted'
77     # fmt: on
78     'formatted'
79     # fmt: off
80     ( yield hello )
81     'unformatted'
82     # fmt: on
83
84 def example(session):
85     # fmt: off
86     result = session\
87         .query(models.Customer.id)\
88         .filter(models.Customer.account_id == account_id,
89                 models.Customer.email == email_address)\
90         .order_by(models.Customer.id.asc())\
91         .all()
92     # fmt: on
93 def off_and_on_without_data():
94     """All comments here are technically on the same prefix.
95
96     The comments between will be formatted. This is a known limitation.
97     """
98     # fmt: off
99
100
101         #hey, that won't work
102
103
104     # fmt: on
105     pass
106 def on_and_off_broken():
107     """Another known limitation."""
108     # fmt: on
109     # fmt: off
110     this=should.not_be.formatted()
111     and_=indeed . it  is  not  formatted
112     because . the . handling . inside . generate_ignored_nodes()
113     now . considers . multiple . fmt . directives . within . one . prefix
114     # fmt: on
115     # fmt: off
116         # ...but comments still get reformatted even though they should not be
117     # fmt: on
118 def long_lines():
119     if True:
120         typedargslist.extend(
121             gen_annotated_params(ast_args.kwonlyargs, ast_args.kw_defaults, parameters, implicit_default=True)
122         )
123         # fmt: off
124         a = (
125             unnecessary_bracket()
126         )
127         # fmt: on
128     _type_comment_re = re.compile(
129         r"""
130         ^
131         [\t ]*
132         \#[ ]type:[ ]*
133         (?P<type>
134             [^#\t\n]+?
135         )
136         (?<!ignore)     # note: this will force the non-greedy + in <type> to match
137                         # a trailing space which is why we need the silliness below
138         (?<!ignore[ ]{1})(?<!ignore[ ]{2})(?<!ignore[ ]{3})(?<!ignore[ ]{4})
139         (?<!ignore[ ]{5})(?<!ignore[ ]{6})(?<!ignore[ ]{7})(?<!ignore[ ]{8})
140         (?<!ignore[ ]{9})(?<!ignore[ ]{10})
141         [\t ]*
142         (?P<nl>
143             (?:\#[^\n]*)?
144             \n?
145         )
146         $
147         """,
148         # fmt: off
149         re.MULTILINE|re.VERBOSE
150         # fmt: on
151     )
152 def single_literal_yapf_disable():
153     """Black does not support this."""
154     BAZ = {
155         (1, 2, 3, 4),
156         (5, 6, 7, 8),
157         (9, 10, 11, 12)
158     }  # yapf: disable
159 cfg.rule(
160     "Default", "address",
161     xxxx_xxxx=["xxx-xxxxxx-xxxxxxxxxx"],
162     xxxxxx="xx_xxxxx", xxxxxxx="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
163     xxxxxxxxx_xxxx=True, xxxxxxxx_xxxxxxxxxx=False,
164     xxxxxx_xxxxxx=2, xxxxxx_xxxxx_xxxxxxxx=70, xxxxxx_xxxxxx_xxxxx=True,
165     # fmt: off
166     xxxxxxx_xxxxxxxxxxxx={
167         "xxxxxxxx": {
168             "xxxxxx": False,
169             "xxxxxxx": False,
170             "xxxx_xxxxxx": "xxxxx",
171         },
172         "xxxxxxxx-xxxxx": {
173             "xxxxxx": False,
174             "xxxxxxx": True,
175             "xxxx_xxxxxx": "xxxxxx",
176         },
177     },
178     # fmt: on
179     xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5
180 )
181 # fmt: off
182 yield  'hello'
183 # No formatting to the end of the file
184 l=[1,2,3]
185 d={'a':1,
186    'b':2}
187
188 # output
189
190
191 #!/usr/bin/env python3
192 import asyncio
193 import sys
194
195 from third_party import X, Y, Z
196
197 from library import some_connection, some_decorator
198
199 # fmt: off
200 from third_party import (X,
201                          Y, Z)
202 # fmt: on
203 f"trigger 3.6 mode"
204 # Comment 1
205
206 # Comment 2
207
208
209 # fmt: off
210 def func_no_args():
211   a; b; c
212   if True: raise RuntimeError
213   if False: ...
214   for i in range(10):
215     print(i)
216     continue
217   exec('new-style exec', {}, {})
218   return None
219 async def coroutine(arg, exec=False):
220  'Single-line docstring. Multiline is harder to reformat.'
221  async with some_connection() as conn:
222      await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2)
223  await asyncio.sleep(1)
224 @asyncio.coroutine
225 @some_decorator(
226 with_args=True,
227 many_args=[1,2,3]
228 )
229 def function_signature_stress_test(number:int,no_annotation=None,text:str='default',* ,debug:bool=False,**kwargs) -> str:
230  return text[number:-1]
231 # fmt: on
232 def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r""):
233     offset = attr.ib(default=attr.Factory(lambda: _r.uniform(1, 2)))
234     assert task._cancel_stack[: len(old_stack)] == old_stack
235
236
237 def spaces_types(
238     a: int = 1,
239     b: tuple = (),
240     c: list = [],
241     d: dict = {},
242     e: bool = True,
243     f: int = -1,
244     g: int = 1 if False else 2,
245     h: str = "",
246     i: str = r"",
247 ):
248     ...
249
250
251 def spaces2(result=_core.Value(None)):
252     ...
253
254
255 something = {
256     # fmt: off
257     key: 'value',
258 }
259
260
261 def subscriptlist():
262     atom[
263         # fmt: off
264         'some big and',
265         'complex subscript',
266         # fmt: on
267         goes + here,
268         andhere,
269     ]
270
271
272 def import_as_names():
273     # fmt: off
274     from hello import a,        b
275     'unformatted'
276     # fmt: on
277
278
279 def testlist_star_expr():
280     # fmt: off
281     a , b = *hello
282     'unformatted'
283     # fmt: on
284
285
286 def yield_expr():
287     # fmt: off
288     yield hello
289     'unformatted'
290     # fmt: on
291     "formatted"
292     # fmt: off
293     ( yield hello )
294     'unformatted'
295     # fmt: on
296
297
298 def example(session):
299     # fmt: off
300     result = session\
301         .query(models.Customer.id)\
302         .filter(models.Customer.account_id == account_id,
303                 models.Customer.email == email_address)\
304         .order_by(models.Customer.id.asc())\
305         .all()
306     # fmt: on
307
308
309 def off_and_on_without_data():
310     """All comments here are technically on the same prefix.
311
312     The comments between will be formatted. This is a known limitation.
313     """
314     # fmt: off
315
316     # hey, that won't work
317
318     # fmt: on
319     pass
320
321
322 def on_and_off_broken():
323     """Another known limitation."""
324     # fmt: on
325     # fmt: off
326     this=should.not_be.formatted()
327     and_=indeed . it  is  not  formatted
328     because . the . handling . inside . generate_ignored_nodes()
329     now . considers . multiple . fmt . directives . within . one . prefix
330     # fmt: on
331     # fmt: off
332     # ...but comments still get reformatted even though they should not be
333     # fmt: on
334
335
336 def long_lines():
337     if True:
338         typedargslist.extend(
339             gen_annotated_params(
340                 ast_args.kwonlyargs,
341                 ast_args.kw_defaults,
342                 parameters,
343                 implicit_default=True,
344             )
345         )
346         # fmt: off
347         a = (
348             unnecessary_bracket()
349         )
350         # fmt: on
351     _type_comment_re = re.compile(
352         r"""
353         ^
354         [\t ]*
355         \#[ ]type:[ ]*
356         (?P<type>
357             [^#\t\n]+?
358         )
359         (?<!ignore)     # note: this will force the non-greedy + in <type> to match
360                         # a trailing space which is why we need the silliness below
361         (?<!ignore[ ]{1})(?<!ignore[ ]{2})(?<!ignore[ ]{3})(?<!ignore[ ]{4})
362         (?<!ignore[ ]{5})(?<!ignore[ ]{6})(?<!ignore[ ]{7})(?<!ignore[ ]{8})
363         (?<!ignore[ ]{9})(?<!ignore[ ]{10})
364         [\t ]*
365         (?P<nl>
366             (?:\#[^\n]*)?
367             \n?
368         )
369         $
370         """,
371         # fmt: off
372         re.MULTILINE|re.VERBOSE
373         # fmt: on
374     )
375
376
377 def single_literal_yapf_disable():
378     """Black does not support this."""
379     BAZ = {(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)}  # yapf: disable
380
381
382 cfg.rule(
383     "Default",
384     "address",
385     xxxx_xxxx=["xxx-xxxxxx-xxxxxxxxxx"],
386     xxxxxx="xx_xxxxx",
387     xxxxxxx="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
388     xxxxxxxxx_xxxx=True,
389     xxxxxxxx_xxxxxxxxxx=False,
390     xxxxxx_xxxxxx=2,
391     xxxxxx_xxxxx_xxxxxxxx=70,
392     xxxxxx_xxxxxx_xxxxx=True,
393     # fmt: off
394     xxxxxxx_xxxxxxxxxxxx={
395         "xxxxxxxx": {
396             "xxxxxx": False,
397             "xxxxxxx": False,
398             "xxxx_xxxxxx": "xxxxx",
399         },
400         "xxxxxxxx-xxxxx": {
401             "xxxxxx": False,
402             "xxxxxxx": True,
403             "xxxx_xxxxxx": "xxxxxx",
404         },
405     },
406     # fmt: on
407     xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5,
408 )
409 # fmt: off
410 yield  'hello'
411 # No formatting to the end of the file
412 l=[1,2,3]
413 d={'a':1,
414    'b':2}