]> git.madduck.net Git - etc/vim.git/blob - tests/data/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:

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