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

Don't crash and burn on empty lines with trailing whitespace
[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  ...
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     _type_comment_re = re.compile(
51         r"""
52         ^
53         [\t ]*
54         \#[ ]type:[ ]*
55         (?P<type>
56             [^#\t\n]+?
57         )
58         (?<!ignore)     # note: this will force the non-greedy + in <type> to match
59                         # a trailing space which is why we need the silliness below
60         (?<!ignore[ ]{1})(?<!ignore[ ]{2})(?<!ignore[ ]{3})(?<!ignore[ ]{4})
61         (?<!ignore[ ]{5})(?<!ignore[ ]{6})(?<!ignore[ ]{7})(?<!ignore[ ]{8})
62         (?<!ignore[ ]{9})(?<!ignore[ ]{10})
63         [\t ]*
64         (?P<nl>
65             (?:\#[^\n]*)?
66             \n?
67         )
68         $
69         """, re.MULTILINE | re.VERBOSE
70     )
71
72 # output
73
74
75 #!/usr/bin/env python3
76 import asyncio
77 import sys
78
79 from third_party import X, Y, Z
80
81 from library import some_connection, some_decorator
82
83 f'trigger 3.6 mode'
84
85
86 def func_no_args():
87     a
88     b
89     c
90     if True:
91         raise RuntimeError
92
93     if False:
94         ...
95     for i in range(10):
96         print(i)
97         continue
98
99     exec("new-style exec", {}, {})
100     return None
101
102
103 async def coroutine(arg, exec=False):
104     "Single-line docstring. Multiline is harder to reformat."
105     async with some_connection() as conn:
106         await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2)
107     await asyncio.sleep(1)
108
109
110 @asyncio.coroutine
111 @some_decorator(with_args=True, many_args=[1, 2, 3])
112 def function_signature_stress_test(
113     number: int,
114     no_annotation=None,
115     text: str = "default",
116     *,
117     debug: bool = False,
118     **kwargs,
119 ) -> str:
120     return text[number:-1]
121
122
123 def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r''):
124     offset = attr.ib(default=attr.Factory(lambda: _r.uniform(10000, 200000)))
125     assert task._cancel_stack[:len(old_stack)] == old_stack
126
127
128 def spaces_types(
129     a: int = 1,
130     b: tuple = (),
131     c: list = [],
132     d: dict = {},
133     e: bool = True,
134     f: int = -1,
135     g: int = 1 if False else 2,
136     h: str = "",
137     i: str = r'',
138 ):
139     ...
140
141
142 def spaces2(result=_core.Value(None)):
143     ...
144
145
146 def example(session):
147     result = session.query(models.Customer.id).filter(
148         models.Customer.account_id == account_id, models.Customer.email == email_address
149     ).order_by(
150         models.Customer.id.asc()
151     ).all()
152
153
154 def long_lines():
155     if True:
156         typedargslist.extend(
157             gen_annotated_params(
158                 ast_args.kwonlyargs,
159                 ast_args.kw_defaults,
160                 parameters,
161                 implicit_default=True,
162             )
163         )
164     _type_comment_re = re.compile(
165         r"""
166         ^
167         [\t ]*
168         \#[ ]type:[ ]*
169         (?P<type>
170             [^#\t\n]+?
171         )
172         (?<!ignore)     # note: this will force the non-greedy + in <type> to match
173                         # a trailing space which is why we need the silliness below
174         (?<!ignore[ ]{1})(?<!ignore[ ]{2})(?<!ignore[ ]{3})(?<!ignore[ ]{4})
175         (?<!ignore[ ]{5})(?<!ignore[ ]{6})(?<!ignore[ ]{7})(?<!ignore[ ]{8})
176         (?<!ignore[ ]{9})(?<!ignore[ ]{10})
177         [\t ]*
178         (?P<nl>
179             (?:\#[^\n]*)?
180             \n?
181         )
182         $
183         """,
184         re.MULTILINE | re.VERBOSE,
185     )