9
9
from .type_stub_helpers import some_mod
10
10
11
11
12
- def noop ():
13
- pass
12
+ def noop (): ...
14
13
15
14
16
- def arg_no_anno (arg1 ):
17
- pass
15
+ def arg_no_anno (arg1 ): ...
18
16
19
17
20
18
def scalar_args (arg1 : str , arg2 : int ) -> float :
21
- pass
19
+ return 0
22
20
23
21
24
- def generic_other_module_arg (arg : typing .List [some_mod .Foo ]):
25
- pass
22
+ def generic_other_module_arg (arg : typing .List [some_mod .Foo ]): ...
26
23
27
24
28
25
async def async_func () -> str :
@@ -154,8 +151,7 @@ def test_wrapped_function_with_new_annotations():
154
151
This test makes sure we do just that.
155
152
"""
156
153
157
- def orig (arg : str ):
158
- pass
154
+ def orig (arg : str ): ...
159
155
160
156
@functools .wraps (orig )
161
157
def wrapper (extra_arg : int , * args , ** kwargs ):
@@ -167,7 +163,7 @@ def wrapper(extra_arg: int, *args, **kwargs):
167
163
168
164
class Base :
169
165
def base_method (self ) -> str :
170
- pass
166
+ return ""
171
167
172
168
173
169
Base .__module__ = "basemod"
@@ -176,7 +172,7 @@ def base_method(self) -> str:
176
172
177
173
class Based (Base ):
178
174
def sub (self ) -> float :
179
- pass
175
+ return 0
180
176
181
177
182
178
def test_base_class_included_and_imported ():
@@ -191,7 +187,7 @@ def test_typevar():
191
187
T .__module__ = "source_mod"
192
188
193
189
def foo (arg : T ) -> T :
194
- pass
190
+ return arg
195
191
196
192
src = _function_source (foo )
197
193
assert "import source_mod" in src
@@ -206,12 +202,10 @@ def test_string_annotation():
206
202
207
203
208
204
class Forwarder :
209
- def foo (self ) -> typing .Optional ["Forwardee" ]:
210
- pass
205
+ def foo (self ) -> typing .Optional ["Forwardee" ]: ...
211
206
212
207
213
- class Forwardee :
214
- pass
208
+ class Forwardee : ...
215
209
216
210
217
211
def test_forward_ref ():
@@ -228,7 +222,7 @@ def test_forward_ref():
228
222
229
223
class SelfRefFoo :
230
224
def foo (self ) -> "SelfRefFoo" :
231
- pass
225
+ return self
232
226
233
227
234
228
def test_self_ref ():
@@ -241,7 +235,7 @@ def test_self_ref():
241
235
class _Foo :
242
236
@staticmethod
243
237
async def clone (foo : "_Foo" ) -> "_Foo" :
244
- pass
238
+ return foo
245
239
246
240
247
241
synchronizer = synchronicity .Synchronizer ()
@@ -250,7 +244,7 @@ async def clone(foo: "_Foo") -> "_Foo":
250
244
251
245
def test_synchronicity_type_translation ():
252
246
async def _get_foo (foo : _Foo ) -> _Foo :
253
- pass
247
+ return foo
254
248
255
249
get_foo = synchronizer .create_blocking (_get_foo , "get_foo" , __name__ )
256
250
src = _function_source (get_foo )
@@ -271,8 +265,7 @@ def test_synchronicity_self_ref():
271
265
272
266
class _WithClassMethod :
273
267
@classmethod
274
- def classy (cls ):
275
- pass
268
+ def classy (cls ): ...
276
269
277
270
async def meth (self , arg : bool ) -> int :
278
271
return 0
@@ -306,8 +299,7 @@ async def aio(self, *args, **kwargs) -> int:
306
299
T = typing .TypeVar ("T" )
307
300
308
301
309
- class MyGeneric (typing .Generic [T ]):
310
- pass
302
+ class MyGeneric (typing .Generic [T ]): ...
311
303
312
304
313
305
BlockingGeneric = synchronizer .create_blocking (typing .Generic , "BlockingGeneric" , __name__ )
@@ -320,16 +312,14 @@ class MyGeneric(typing.Generic[T]):
320
312
321
313
def test_custom_generic ():
322
314
# TODO: build out this test a bit, as it currently creates an invalid stub (missing base types)
323
- class Specific (MyGeneric [str ]):
324
- pass
315
+ class Specific (MyGeneric [str ]): ...
325
316
326
317
src = _class_source (Specific )
327
318
assert "class Specific(MyGeneric[str]):" in src
328
319
329
320
330
321
def test_synchronicity_generic_subclass ():
331
- class Specific (MyGeneric [str ]):
332
- pass
322
+ class Specific (MyGeneric [str ]): ...
333
323
334
324
assert Specific .__bases__ == (MyGeneric ,)
335
325
assert Specific .__orig_bases__ == (MyGeneric [str ],)
@@ -338,8 +328,7 @@ class Specific(MyGeneric[str]):
338
328
src = _class_source (BlockingSpecific )
339
329
assert "class BlockingSpecific(BlockingMyGeneric[str]):" in src
340
330
341
- async def foo_impl (bar : MyGeneric [str ]):
342
- pass
331
+ async def foo_impl (bar : MyGeneric [str ]): ...
343
332
344
333
foo = synchronizer .create_blocking (foo_impl , "foo" )
345
334
src = _function_source (foo )
@@ -372,14 +361,15 @@ def test_translated_bound_type_vars():
372
361
373
362
def test_ellipsis ():
374
363
def foo () -> typing .Callable [..., typing .Any ]:
375
- pass
364
+ return lambda x : 0
376
365
377
366
src = _function_source (foo )
378
367
assert "-> typing.Callable[..., typing.Any]" in src
379
368
380
369
381
370
def test_typing_literal ():
382
- def foo () -> typing .Literal ["three" , "str" ]: ...
371
+ def foo () -> typing .Literal ["three" , "str" ]:
372
+ return "str"
383
373
384
374
src = _function_source (foo )
385
375
assert "-> typing.Literal['three', 'str']" in src # "str" should not be eval:ed in a Literal!
@@ -389,12 +379,10 @@ def test_overloads_unwrapped_functions():
389
379
with overload_tracking .patched_overload ():
390
380
391
381
@typing .overload
392
- def _overloaded (arg : str ) -> float :
393
- pass
382
+ def _overloaded (arg : str ) -> float : ...
394
383
395
384
@typing .overload
396
- def _overloaded (arg : int ) -> int :
397
- pass
385
+ def _overloaded (arg : int ) -> int : ...
398
386
399
387
def _overloaded (arg : typing .Union [str , int ]):
400
388
if isinstance (arg , str ):
0 commit comments