]> git.madduck.net Git - etc/vim.git/blob - tests/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 optional parentheses being removed within `# fmt: off` sections
[etc/vim.git] / tests / 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 f'trigger 3.6 mode'
10 # fmt: off
11 def func_no_args():
12   a; b; c
13   if True: raise RuntimeError
14   if False: ...
15   for i in range(10):
16     print(i)
17     continue
18   exec('new-style exec', {}, {})
19   return None
20 async def coroutine(arg, exec=False):
21  'Single-line docstring. Multiline is harder to reformat.'
22  async with some_connection() as conn:
23      await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2)
24  await asyncio.sleep(1)
25 @asyncio.coroutine
26 @some_decorator(
27 with_args=True,
28 many_args=[1,2,3]
29 )
30 def function_signature_stress_test(number:int,no_annotation=None,text:str='default',* ,debug:bool=False,**kwargs) -> str:
31  return text[number:-1]
32 # fmt: on
33 def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r''):
34  offset = attr.ib(default=attr.Factory( lambda: _r.uniform(10000, 200000)))
35  assert task._cancel_stack[:len(old_stack)] == old_stack
36 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''): ...
37 def spaces2(result= _core.Value(None)):
38  ...
39 def example(session):
40     # fmt: off
41     result = session\
42         .query(models.Customer.id)\
43         .filter(models.Customer.account_id == account_id,
44                 models.Customer.email == email_address)\
45         .order_by(models.Customer.id.asc())\
46         .all()
47     # fmt: on
48 def long_lines():
49     if True:
50         typedargslist.extend(
51             gen_annotated_params(ast_args.kwonlyargs, ast_args.kw_defaults, parameters, implicit_default=True)
52         )
53         # fmt: off
54         a = (
55             unnecessary_bracket()
56         )
57         # fmt: on
58     _type_comment_re = re.compile(
59         r"""
60         ^
61         [\t ]*
62         \#[ ]type:[ ]*
63         (?P<type>
64             [^#\t\n]+?
65         )
66         (?<!ignore)     # note: this will force the non-greedy + in <type> to match
67                         # a trailing space which is why we need the silliness below
68         (?<!ignore[ ]{1})(?<!ignore[ ]{2})(?<!ignore[ ]{3})(?<!ignore[ ]{4})
69         (?<!ignore[ ]{5})(?<!ignore[ ]{6})(?<!ignore[ ]{7})(?<!ignore[ ]{8})
70         (?<!ignore[ ]{9})(?<!ignore[ ]{10})
71         [\t ]*
72         (?P<nl>
73             (?:\#[^\n]*)?
74             \n?
75         )
76         $
77         """, # fmt: off
78         re.MULTILINE | re.VERBOSE
79     )
80     # fmt: on
81 def single_literal_yapf_disable():
82     """Black does not support this."""
83     BAZ = {
84         (1, 2, 3, 4),
85         (5, 6, 7, 8),
86         (9, 10, 11, 12),
87     }  # yapf: disable
88 # fmt: off
89 # No formatting to the end of the file
90 l=[1,2,3]
91 d={'a':1,
92    'b':2}
93
94 # output
95
96
97 #!/usr/bin/env python3
98 import asyncio
99 import sys
100
101 from third_party import X, Y, Z
102
103 from library import some_connection, some_decorator
104
105 f"trigger 3.6 mode"
106 # fmt: off
107 def func_no_args():
108   a; b; c
109   if True: raise RuntimeError
110   if False: ...
111   for i in range(10):
112     print(i)
113     continue
114   exec('new-style exec', {}, {})
115   return None
116 async def coroutine(arg, exec=False):
117  'Single-line docstring. Multiline is harder to reformat.'
118  async with some_connection() as conn:
119      await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2)
120  await asyncio.sleep(1)
121 @asyncio.coroutine
122 @some_decorator(
123 with_args=True,
124 many_args=[1,2,3]
125 )
126 def function_signature_stress_test(number:int,no_annotation=None,text:str='default',* ,debug:bool=False,**kwargs) -> str:
127  return text[number:-1]
128 # fmt: on
129 def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r""):
130     offset = attr.ib(default=attr.Factory(lambda: _r.uniform(10000, 200000)))
131     assert task._cancel_stack[: len(old_stack)] == old_stack
132
133
134 def spaces_types(
135     a: int = 1,
136     b: tuple = (),
137     c: list = [],
138     d: dict = {},
139     e: bool = True,
140     f: int = -1,
141     g: int = 1 if False else 2,
142     h: str = "",
143     i: str = r"",
144 ):
145     ...
146
147
148 def spaces2(result=_core.Value(None)):
149     ...
150
151
152 def example(session):
153     # fmt: off
154     result = session\
155         .query(models.Customer.id)\
156         .filter(models.Customer.account_id == account_id,
157                 models.Customer.email == email_address)\
158         .order_by(models.Customer.id.asc())\
159         .all()
160     # fmt: on
161
162
163 def long_lines():
164     if True:
165         typedargslist.extend(
166             gen_annotated_params(
167                 ast_args.kwonlyargs,
168                 ast_args.kw_defaults,
169                 parameters,
170                 implicit_default=True,
171             )
172         )
173         # fmt: off
174         a = (
175             unnecessary_bracket()
176         )
177         # fmt: on
178     _type_comment_re = re.compile(
179         r"""
180         ^
181         [\t ]*
182         \#[ ]type:[ ]*
183         (?P<type>
184             [^#\t\n]+?
185         )
186         (?<!ignore)     # note: this will force the non-greedy + in <type> to match
187                         # a trailing space which is why we need the silliness below
188         (?<!ignore[ ]{1})(?<!ignore[ ]{2})(?<!ignore[ ]{3})(?<!ignore[ ]{4})
189         (?<!ignore[ ]{5})(?<!ignore[ ]{6})(?<!ignore[ ]{7})(?<!ignore[ ]{8})
190         (?<!ignore[ ]{9})(?<!ignore[ ]{10})
191         [\t ]*
192         (?P<nl>
193             (?:\#[^\n]*)?
194             \n?
195         )
196         $
197         """,  # fmt: off
198         re.MULTILINE | re.VERBOSE,
199     )
200     # fmt: on
201
202
203 def single_literal_yapf_disable():
204     """Black does not support this."""
205     BAZ = {(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)}  # yapf: disable
206
207
208 # fmt: off
209 # No formatting to the end of the file
210 l=[1,2,3]
211 d={'a':1,
212    'b':2}