File tree Expand file tree Collapse file tree 3 files changed +17
-8
lines changed Expand file tree Collapse file tree 3 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -512,13 +512,14 @@ def generate_tokens(readline):
512
512
stashed = tok
513
513
continue
514
514
515
- if token == 'def' :
515
+ if token in ( 'def' , 'for' ) :
516
516
if (stashed
517
517
and stashed [0 ] == NAME
518
518
and stashed [1 ] == 'async' ):
519
519
520
- async_def = True
521
- async_def_indent = indents [- 1 ]
520
+ if token == 'def' :
521
+ async_def = True
522
+ async_def_indent = indents [- 1 ]
522
523
523
524
yield (ASYNC , stashed [1 ],
524
525
stashed [2 ], stashed [3 ],
Original file line number Diff line number Diff line change @@ -200,20 +200,27 @@ def test_async_var(self):
200
200
self .validate ("""await = 1""" )
201
201
self .validate ("""def async(): pass""" )
202
202
203
- def test_async_with (self ):
203
+ def test_async_for (self ):
204
204
self .validate ("""async def foo():
205
205
async for a in b: pass""" )
206
206
207
- self .invalid_syntax ("""def foo():
208
- async for a in b: pass""" )
209
-
210
- def test_async_for (self ):
207
+ def test_async_with (self ):
211
208
self .validate ("""async def foo():
212
209
async with a: pass""" )
213
210
214
211
self .invalid_syntax ("""def foo():
215
212
async with a: pass""" )
216
213
214
+ def test_async_generator (self ):
215
+ self .validate (
216
+ """async def foo():
217
+ return (i * 2 async for i in arange(42))"""
218
+ )
219
+ self .validate (
220
+ """def foo():
221
+ return (i * 2 async for i in arange(42))"""
222
+ )
223
+
217
224
218
225
class TestRaiseChanges (GrammarTest ):
219
226
def test_2x_style_1 (self ):
Original file line number Diff line number Diff line change
1
+ lib2to3 now recognizes async generators everywhere.
You can’t perform that action at this time.
0 commit comments