Skip to content

Commit 61d1148

Browse files
authored
Merge pull request #3222 from WarriorOfWire/pick_micropython
py/compile: Don't await __aiter__ special method in async-for.
2 parents 5e86262 + 901f3dc commit 61d1148

File tree

4 files changed

+5
-9
lines changed

4 files changed

+5
-9
lines changed

py/compile.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,8 @@ STATIC void compile_async_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns
17411741
uint try_finally_label = comp_next_label(comp);
17421742

17431743
compile_node(comp, pns->nodes[1]); // iterator
1744-
compile_await_object_method(comp, MP_QSTR___aiter__);
1744+
EMIT_ARG(load_method, MP_QSTR___aiter__, false);
1745+
EMIT_ARG(call_method, 0, 0, 0);
17451746
compile_store_id(comp, context);
17461747

17471748
START_BREAK_CONTINUE_BLOCK

tests/basics/async_for.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def __init__(self, obj):
66
print('init')
77
self._it = iter(obj)
88

9-
async def __aiter__(self):
9+
def __aiter__(self):
1010
print('aiter')
1111
return self
1212

tests/basics/async_for2.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# test waiting within "async for" aiter/anext functions
1+
# test waiting within "async for" __anext__ function
22

33
import sys
44
if sys.implementation.name in ('micropython', 'circuitpython'):
@@ -21,9 +21,8 @@ def __init__(self, high):
2121
self.cur = 0
2222
self.high = high
2323

24-
async def __aiter__(self):
24+
def __aiter__(self):
2525
print('aiter')
26-
print('f returned:', await f(10))
2726
return self
2827

2928
async def __anext__(self):

tests/basics/async_for2.py.exp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
init
22
aiter
3-
f start: 10
4-
coro yielded: 11
5-
coro yielded: 12
6-
f returned: 13
73
anext
84
f start: 20
95
coro yielded: 21

0 commit comments

Comments
 (0)