File tree Expand file tree Collapse file tree 1 file changed +29
-4
lines changed Expand file tree Collapse file tree 1 file changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -57,12 +57,37 @@ async def __anext__(self):
5757 return 1
5858
5959 async def callback (v ):
60- raise RuntimeError
60+ raise RuntimeError ()
6161
6262 inner = Inner ()
6363 outer = map_async_iterable (inner , callback )
64- it = outer .__aiter__ ()
65- assert not inner .closed
6664 with raises (RuntimeError ):
67- await it .__anext__ ()
65+ async for _ in outer :
66+ pass
6867 assert inner .closed
68+
69+ @mark .asyncio
70+ async def test_inner_exit_on_callback_err ():
71+ """
72+ Test that a custom iterator with aclose() gets an aclose() call
73+ when the callback errors and the outer iterator aborts.
74+ """
75+
76+ inner_exit = False
77+
78+ async def inner ():
79+ nonlocal inner_exit
80+ try :
81+ while True :
82+ yield 1
83+ except GeneratorExit :
84+ inner_exit = True
85+
86+ async def callback (v ):
87+ raise RuntimeError
88+
89+ outer = map_async_iterable (inner (), callback )
90+ with raises (RuntimeError ):
91+ async for _ in outer :
92+ pass
93+ assert inner_exit
You can’t perform that action at this time.
0 commit comments