Skip to content

Commit 7a05f9a

Browse files
committed
Add test for async list comprehension
1 parent 0e39bd3 commit 7a05f9a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Lib/test/test_coroutines.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,6 +2265,30 @@ def c():
22652265
# before fixing, visible stack from throw would be shorter than from send.
22662266
self.assertEqual(len_send, len_throw)
22672267

2268+
def test_call_aiter_once_in_comprehension(self):
2269+
2270+
class Iterator:
2271+
2272+
def __init__(self):
2273+
self.val = 0
2274+
2275+
async def __anext__(self):
2276+
if self.val == 2:
2277+
raise StopAsyncIteration
2278+
self.val += 1
2279+
return self.val
2280+
2281+
# No __aiter__ method
2282+
2283+
class C:
2284+
2285+
def __aiter__(self):
2286+
return Iterator()
2287+
2288+
async def run():
2289+
return [i async for i in C()]
2290+
2291+
self.assertEqual(run_async(run()), ([], [1,2]))
22682292

22692293
@unittest.skipIf(
22702294
support.is_emscripten or support.is_wasi,

0 commit comments

Comments
 (0)