Debian Codegraph @

tests/data/cases/function.py

raw
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 def f(
85 a,
86 **kwargs,
87 ) -> A:
88 return (
89 yield from A(
90 very_long_argument_name1=very_long_value_for_the_argument,
91 very_long_argument_name2=very_long_value_for_the_argument,
92 **kwargs,
93 )
94 )
95 def __await__(): return (yield)
96
97 # output
98
99
100 #!/usr/bin/env python3
101 import asyncio
102 import sys
103
104 from third_party import X, Y, Z
105
106 from library import some_connection, some_decorator
107
108 f"trigger 3.6 mode"
109
110
111 def func_no_args():
112 a
113 b
114 c
115 if True:
116 raise RuntimeError
117 if False:
118 ...
119 for i in range(10):
120 print(i)
121 continue
122 exec("new-style exec", {}, {})
123 return None
124
125
126 async def coroutine(arg, exec=False):
127 "Single-line docstring. Multiline is harder to reformat."
128 async with some_connection() as conn:
129 await conn.do_what_i_mean("SELECT bobby, tables FROM xkcd", timeout=2)
130 await asyncio.sleep(1)
131
132
133 @asyncio.coroutine
134 @some_decorator(with_args=True, many_args=[1, 2, 3])
135 def function_signature_stress_test(
136 number: int,
137 no_annotation=None,
138 text: str = "default",
139 *,
140 debug: bool = False,
141 **kwargs,
142 ) -> str:
143 return text[number:-1]
144
145
146 def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r""):
147 offset = attr.ib(default=attr.Factory(lambda: _r.uniform(10000, 200000)))
148 assert task._cancel_stack[: len(old_stack)] == old_stack
149
150
151 def spaces_types(
152 a: int = 1,
153 b: tuple = (),
154 c: list = [],
155 d: dict = {},
156 e: bool = True,
157 f: int = -1,
158 g: int = 1 if False else 2,
159 h: str = "",
160 i: str = r"",
161 ): ...
162 def spaces2(result=_core.Value(None)):
163 assert fut is self._read_fut, (fut, self._read_fut)
164
165
166 def example(session):
167 result = (
168 session.query(models.Customer.id)
169 .filter(
170 models.Customer.account_id == account_id,
171 models.Customer.email == email_address,
172 )
173 .order_by(models.Customer.id.asc())
174 .all()
175 )
176
177
178 def long_lines():
179 if True:
180 typedargslist.extend(
181 gen_annotated_params(
182 ast_args.kwonlyargs,
183 ast_args.kw_defaults,
184 parameters,
185 implicit_default=True,
186 )
187 )
188 typedargslist.extend(
189 gen_annotated_params(
190 ast_args.kwonlyargs,
191 ast_args.kw_defaults,
192 parameters,
193 implicit_default=True,
194 # trailing standalone comment
195 )
196 )
197 _type_comment_re = re.compile(
198 r"""
199 ^
200 [\t ]*
201 \#[ ]type:[ ]*
202 (?P<type>
203 [^#\t\n]+?
204 )
205 (?<!ignore) # note: this will force the non-greedy + in <type> to match
206 # a trailing space which is why we need the silliness below
207 (?<!ignore[ ]{1})(?<!ignore[ ]{2})(?<!ignore[ ]{3})(?<!ignore[ ]{4})
208 (?<!ignore[ ]{5})(?<!ignore[ ]{6})(?<!ignore[ ]{7})(?<!ignore[ ]{8})
209 (?<!ignore[ ]{9})(?<!ignore[ ]{10})
210 [\t ]*
211 (?P<nl>
212 (?:\#[^\n]*)?
213 \n?
214 )
215 $
216 """,
217 re.MULTILINE | re.VERBOSE,
218 )
219
220
221 def trailing_comma():
222 mapping = {
223 A: 0.25 * (10.0 / 12),
224 B: 0.1 * (10.0 / 12),
225 C: 0.1 * (10.0 / 12),
226 D: 0.1 * (10.0 / 12),
227 }
228
229
230 def f(
231 a,
232 **kwargs,
233 ) -> A:
234 return (
235 yield from A(
236 very_long_argument_name1=very_long_value_for_the_argument,
237 very_long_argument_name2=very_long_value_for_the_argument,
238 **kwargs,
239 )
240 )
241
242
243 def __await__():
244 return (yield)