-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also fix returning a value from inside a try block when the finally block does a yield. (Which happens when returning from an async with). Progress on mypyc/mypyc##868.
- Loading branch information
Showing
8 changed files
with
152 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# async test cases (compile and run) | ||
|
||
[case testAsync] | ||
import asyncio | ||
|
||
async def h() -> int: | ||
return 1 | ||
|
||
async def g() -> int: | ||
await asyncio.sleep(0) | ||
return await h() | ||
|
||
async def f() -> int: | ||
return await g() | ||
|
||
[typing fixtures/typing-full.pyi] | ||
|
||
[file driver.py] | ||
from native import f | ||
import asyncio | ||
|
||
result = asyncio.run(f()) | ||
assert result == 1 | ||
|
||
[case testAsyncWith] | ||
from testutil import async_val | ||
|
||
class async_ctx: | ||
async def __aenter__(self) -> str: | ||
await async_val("enter") | ||
return "test" | ||
|
||
async def __aexit__(self, x, y, z) -> None: | ||
await async_val("exit") | ||
|
||
|
||
async def async_with() -> str: | ||
async with async_ctx() as x: | ||
return await async_val("body") | ||
|
||
|
||
[file driver.py] | ||
from native import async_with | ||
from testutil import run_generator | ||
|
||
yields, val = run_generator(async_with(), [None, 'x', None]) | ||
assert yields == ('enter', 'body', 'exit'), yields | ||
assert val == 'x', val | ||
|
||
|
||
[case testAsyncReturn] | ||
from testutil import async_val | ||
|
||
async def async_return() -> str: | ||
try: | ||
return 'test' | ||
finally: | ||
await async_val('foo') | ||
|
||
[file driver.py] | ||
from native import async_return | ||
from testutil import run_generator | ||
|
||
yields, val = run_generator(async_return()) | ||
assert yields == ('foo',) | ||
assert val == 'test', val |
Oops, something went wrong.