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 @@ -513,13 +513,14 @@ def generate_tokens(readline):
513
513
stashed = tok
514
514
continue
515
515
516
- if token == 'def' :
516
+ if token in ( 'def' , 'for' ) :
517
517
if (stashed
518
518
and stashed [0 ] == NAME
519
519
and stashed [1 ] == 'async' ):
520
520
521
- async_def = True
522
- async_def_indent = indents [- 1 ]
521
+ if token == 'def' :
522
+ async_def = True
523
+ async_def_indent = indents [- 1 ]
523
524
524
525
yield (ASYNC , stashed [1 ],
525
526
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