| 1 |
""" |
| 2 |
Tests for all async use cases. |
| 3 |
|
| 4 |
Currently we're not supporting completion of them, but they should at least not |
| 5 |
raise errors or return extremely strange results. |
| 6 |
""" |
| 7 |
|
| 8 |
async def x(): |
| 9 |
return 1 |
| 10 |
|
| 11 |
|
| 12 |
x.cr_awai |
| 13 |
|
| 14 |
|
| 15 |
x().cr_awai |
| 16 |
|
| 17 |
a = await x() |
| 18 |
|
| 19 |
a |
| 20 |
|
| 21 |
async def y(): |
| 22 |
argh = await x() |
| 23 |
|
| 24 |
argh |
| 25 |
|
| 26 |
x().__await__().__next |
| 27 |
return 2 |
| 28 |
|
| 29 |
class A(): |
| 30 |
@staticmethod |
| 31 |
async def b(c=1, d=2): |
| 32 |
return 1 |
| 33 |
|
| 34 |
|
| 35 |
await A.b() |
| 36 |
|
| 37 |
|
| 38 |
await A.b(d=3) |
| 39 |
|
| 40 |
class Awaitable: |
| 41 |
def __await__(self): |
| 42 |
yield None |
| 43 |
return '' |
| 44 |
|
| 45 |
async def awaitable_test(): |
| 46 |
foo = await Awaitable() |
| 47 |
|
| 48 |
foo |
| 49 |
|
| 50 |
async def asgen(): |
| 51 |
yield 1 |
| 52 |
await asyncio.sleep(0) |
| 53 |
yield 2 |
| 54 |
|
| 55 |
async def wrapper(): |
| 56 |
|
| 57 |
[x async for x in asgen()][0] |
| 58 |
|
| 59 |
async for y in asgen(): |
| 60 |
|
| 61 |
y |
| 62 |
|
| 63 |
|
| 64 |
asgen().__ane |
| 65 |
|
| 66 |
asgen().mro |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
normal_var1 = 42 |
| 71 |
|
| 72 |
async def foo(): |
| 73 |
normal_var2 = False |
| 74 |
|
| 75 |
normal_var |
| 76 |
|
| 77 |
|
| 78 |
class C: |
| 79 |
@classmethod |
| 80 |
async def async_for_classmethod(cls) -> "C": |
| 81 |
return |
| 82 |
|
| 83 |
async def async_for_method(cls) -> int: |
| 84 |
return |
| 85 |
|
| 86 |
|
| 87 |
async def f(): |
| 88 |
c = await C.async_for_method() |
| 89 |
|
| 90 |
c |
| 91 |
d = await C().async_for_method() |
| 92 |
|
| 93 |
d |
| 94 |
|
| 95 |
e = await C.async_for_classmethod() |
| 96 |
|
| 97 |
e |
| 98 |
f = await C().async_for_classmethod() |
| 99 |
|
| 100 |
f |
| 101 |
|
| 102 |
|
| 103 |
class AsyncCtxMgr: |
| 104 |
def some_method(): |
| 105 |
pass |
| 106 |
|
| 107 |
async def __aenter__(self): |
| 108 |
return self |
| 109 |
|
| 110 |
async def __aexit__(self, *args): |
| 111 |
pass |
| 112 |
|
| 113 |
|
| 114 |
async def asyncctxmgr(): |
| 115 |
async with AsyncCtxMgr() as acm: |
| 116 |
|
| 117 |
acm |
| 118 |
|
| 119 |
acm.som |