Implement better handling for async for.

Instead of ignoring boilerplate when decompiling `async for`, build the loop semantically by deconstructing the BLK_WHILE -> BLK_CONTAINER -> BLK_TRY that python generates when compiling an `async for` (see https://www.python.org/dev/peps/pep-0492/#asynchronous-iterators-and-async-for).
When reading GET_AITER, convert the BLK_WHILE into a BLK_ASYNCFOR in the same way as a `for` loop.
Ignore GET_ANEXT.
Use END_FINALLY as the trigger to finish building the BLK_ASYNCFOR:
-> Extract the loop variable from the contents of the BLK_TRY.
-> Throw away the BLK_TRY and BLK_CONTAINER, leave the BLK_ASYNCFOR on top of the stack.
This commit is contained in:
Aralox
2020-10-21 19:32:20 +11:00
parent 8933c9a4a9
commit 91a23f914d
5 changed files with 67 additions and 128 deletions

View File

@@ -21,7 +21,7 @@ break <EOL>
<OUTDENT>
async def time_for_some_fun ( ) : <EOL>
<INDENT>
async for x , y in myfunc ( c ) : <EOL>
async for ( x , y ) in myfunc ( c ) : <EOL>
<INDENT>
print ( 123 ) <EOL>
if x == 3 : <EOL>
@@ -54,7 +54,7 @@ print ( 'ridiculous nesting' ) <EOL>
<OUTDENT>
<OUTDENT>
<OUTDENT>
async for q , w , e , r in qwer : <EOL>
async for ( q , w , e , r ) in qwer : <EOL>
<INDENT>
u = 6 <EOL>
<OUTDENT>