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 @@ -196,20 +196,27 @@ def test_async_var(self):
196
196
self .validate ("""await = 1""" )
197
197
self .validate ("""def async(): pass""" )
198
198
199
- def test_async_with (self ):
199
+ def test_async_for (self ):
200
200
self .validate ("""async def foo():
201
201
async for a in b: pass""" )
202
202
203
- self .invalid_syntax ("""def foo():
204
- async for a in b: pass""" )
205
-
206
- def test_async_for (self ):
203
+ def test_async_with (self ):
207
204
self .validate ("""async def foo():
208
205
async with a: pass""" )
209
206
210
207
self .invalid_syntax ("""def foo():
211
208
async with a: pass""" )
212
209
210
+ def test_async_generator (self ):
211
+ self .validate (
212
+ """async def foo():
213
+ return (i * 2 async for i in arange(42))"""
214
+ )
215
+ self .validate (
216
+ """def foo():
217
+ return (i * 2 async for i in arange(42))"""
218
+ )
219
+
213
220
214
221
class TestRaiseChanges (GrammarTest ):
215
222
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