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

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