Skip to content

Commit 0db01fe

Browse files
committed
More testing
1 parent 318ae87 commit 0db01fe

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

mypyc/test-data/run-async.test

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,16 @@ def run(x: object) -> object: ...
3535
[typing fixtures/typing-full.pyi]
3636

3737
[case testRunAsyncAwaitInVariousPositions]
38+
from typing import cast, Any
39+
3840
import asyncio
3941

4042
async def one() -> int:
43+
await asyncio.sleep(0.0)
4144
return int() + 1
4245

4346
async def true() -> bool:
44-
return bool(int() + 1)
47+
return bool(int() + await one())
4548

4649
async def branch_await() -> int:
4750
if await true():
@@ -124,6 +127,33 @@ async def construct(s: str) -> str:
124127
def test_construct() -> None:
125128
assert asyncio.run(construct("foo")) == "foo!"
126129

130+
async def repr_as_object(s: str) -> object:
131+
return repr(s)
132+
133+
async def do_cast(s: str) -> str:
134+
return cast(str, await repr_as_object(s))
135+
136+
def test_cast() -> None:
137+
assert asyncio.run(do_cast("foo")) == "'foo'"
138+
139+
async def box() -> list[int]:
140+
return [await one(), await one()]
141+
142+
def test_box() -> None:
143+
assert asyncio.run(box()) == [1, 1]
144+
145+
async def int_as_any(n: int) -> Any:
146+
return n * 2
147+
148+
async def inc(n: int) -> int:
149+
return n + await one()
150+
151+
async def unbox(n: int) -> int:
152+
return await inc(await int_as_any(n))
153+
154+
def test_unbox() -> None:
155+
assert asyncio.run(unbox(4)) == 9
156+
127157
[file asyncio/__init__.pyi]
128158
async def sleep(t: float) -> None: ...
129159
# eh, we could use the real type but it doesn't seem important

0 commit comments

Comments
 (0)