@@ -561,3 +561,85 @@ def test_bool() -> None:
561561
562562[file asyncio/__init__.pyi]
563563def run(x: object) -> object: ...
564+
565+ [case testRunAsyncNestedFunctions]
566+ import asyncio
567+ from typing import cast, Iterator
568+
569+ from testutil import assertRaises
570+
571+ def normal_contains_async_def(x: int) -> int:
572+ async def f(y: int) -> int:
573+ return x + y
574+
575+ return 5 + cast(int, asyncio.run(f(6)))
576+
577+ def test_def_contains_async_def() -> None:
578+ assert normal_contains_async_def(3) == 14
579+
580+ async def inc(x: int) -> int:
581+ return x + 1
582+
583+ async def async_def_contains_normal(x: int) -> int:
584+ def nested(y: int, z: int) -> int:
585+ return x + y + z
586+
587+ a = x
588+ a += nested((await inc(3)), (await inc(4)))
589+ return a
590+
591+ def test_async_def_contains_normal() -> None:
592+ assert normal_contains_async_def(2) == (2 + 2 + 4 + 5)
593+
594+ async def async_def_contains_async_def(x: int) -> int:
595+ async def f(y: int) -> int:
596+ return (await inc(x)) + (await inc(y))
597+
598+ return (await f(1)) + (await f(2))
599+
600+ def test_async_def_contains_async_def() -> None:
601+ assert asyncio.run(async_def_contains_async_def(3)) == (3 + 1 + 1 + 1) + (3 + 1 + 2 + 1)
602+
603+ async def async_def_contains_generator(x: int) -> tuple[int, int, int]:
604+ def gen(y: int) -> Iterator[int]:
605+ yield x + 1
606+ yield x + y
607+
608+ it = gen(4)
609+ res = x + 10, next(it), next(it)
610+
611+ with assertRaises(StopIteration):
612+ next(it)
613+
614+ return res
615+
616+ def test_async_def_contains_generator() -> None:
617+ assert asyncio.run(async_def_contains_generator(3)) == (13, 4, 7)
618+
619+ def generator_contains_async_def(x: int) -> Iterator[int]:
620+ async def f(y: int) -> int:
621+ return (await inc(x)) + (await inc(y))
622+
623+ yield cast(int, asyncio.run(f(2)))
624+ yield cast(int, asyncio.run(f(3)))
625+ yield x + 10
626+
627+ def test_generator_contains_async_def() -> None:
628+ assert list(generator_contains_async_def(5)) == [6 + 3, 6 + 4, 15]
629+
630+ async def async_def_contains_two_nested_functions(x: int, y: int) -> tuple[int, int]:
631+ def f(a: int) -> int:
632+ return x + a
633+
634+ def g(b: int, c: int) -> int:
635+ return y + b + c
636+
637+ return (await inc(f(3))), (await inc(g(4, 10)))
638+
639+ def test_async_def_contains_two_nested_functions() -> None:
640+ assert asyncio.run(async_def_contains_two_nested_functions(5, 7)) == (
641+ (5 + 3 + 1), (7 + 4 + 10 + 1)
642+ )
643+
644+ [file asyncio/__init__.pyi]
645+ def run(x: object) -> object: ...
0 commit comments