Skip to content

Commit 079c41d

Browse files
committed
Add test
1 parent 56b8cbb commit 079c41d

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

mypyc/test-data/run-async.test

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,3 +1739,63 @@ async def m_future_with_reraised_exception(first_exc: Exception, second_exc: Exc
17391739
return await make_future(first_exc)
17401740
except type(first_exc):
17411741
raise second_exc
1742+
1743+
[case testCPyFunctionWithFreedInstance]
1744+
import asyncio
1745+
1746+
from functools import wraps
1747+
from typing import Any
1748+
1749+
class ctx_man:
1750+
async def __aenter__(self) -> None:
1751+
pass
1752+
1753+
async def __aexit__(self, *args: Any) -> None:
1754+
pass
1755+
1756+
def with_ctx_man():
1757+
def decorator(f):
1758+
@wraps(f)
1759+
async def inner():
1760+
async with ctx_man():
1761+
return await f()
1762+
1763+
return inner
1764+
1765+
return decorator
1766+
1767+
async def func() -> int:
1768+
return 33
1769+
1770+
async def run_wrapped():
1771+
wrapped = with_ctx_man()(func)
1772+
return await wrapped()
1773+
1774+
def test_native():
1775+
assert asyncio.run(run_wrapped()) == 33
1776+
1777+
[file driver.py]
1778+
import asyncio
1779+
1780+
from native import test_native, with_ctx_man
1781+
1782+
async def func() -> int:
1783+
return 42
1784+
1785+
async def run_wrapped():
1786+
wrapped = with_ctx_man()(func)
1787+
return await wrapped()
1788+
1789+
def test_interpreted():
1790+
assert asyncio.run(run_wrapped()) == 42
1791+
1792+
# Run multiple times to test that the CPyFunction attribute is still
1793+
# set correctly after reusing a freed instance of the inner callable class object.
1794+
for i in range(10):
1795+
test_interpreted()
1796+
test_native()
1797+
1798+
[file asyncio/__init__.pyi]
1799+
from typing import Any, Generator
1800+
1801+
def run(x: object) -> object: ...

0 commit comments

Comments
 (0)