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

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