@@ -33,6 +33,10 @@ async def __aenter__(self):
3333 async def __aexit__ (self , * exc_info ):
3434 self .output .append (- self .value )
3535
36+ async def asynciter (iterable ):
37+ """Convert an iterable to an asynchronous iterator."""
38+ for x in iterable :
39+ yield x
3640
3741
3842# A very basic example. If this fails, we're in deep trouble.
@@ -720,6 +724,23 @@ def test_jump_out_of_block_backwards(output):
720724 output .append (6 )
721725 output .append (7 )
722726
727+ @async_jump_test (4 , 5 , [3 , 5 ])
728+ async def test_jump_out_of_async_for_block_forwards (output ):
729+ for i in [1 ]:
730+ async for i in asynciter ([1 , 2 ]):
731+ output .append (3 )
732+ output .append (4 )
733+ output .append (5 )
734+
735+ @async_jump_test (5 , 2 , [2 , 4 , 2 , 4 , 5 , 6 ])
736+ async def test_jump_out_of_async_for_block_backwards (output ):
737+ for i in [1 ]:
738+ output .append (2 )
739+ async for i in asynciter ([1 ]):
740+ output .append (4 )
741+ output .append (5 )
742+ output .append (6 )
743+
723744 @jump_test (1 , 2 , [3 ])
724745 def test_jump_to_codeless_line (output ):
725746 output .append (1 )
@@ -1030,6 +1051,17 @@ def test_jump_over_for_block_before_else(output):
10301051 output .append (7 )
10311052 output .append (8 )
10321053
1054+ @async_jump_test (1 , 7 , [7 , 8 ])
1055+ async def test_jump_over_async_for_block_before_else (output ):
1056+ output .append (1 )
1057+ if not output : # always false
1058+ async for i in asynciter ([3 ]):
1059+ output .append (4 )
1060+ else :
1061+ output .append (6 )
1062+ output .append (7 )
1063+ output .append (8 )
1064+
10331065 # The second set of 'jump' tests are for things that are not allowed:
10341066
10351067 @jump_test (2 , 3 , [1 ], (ValueError , 'after' ))
@@ -1081,12 +1113,24 @@ def test_no_jump_forwards_into_for_block(output):
10811113 for i in 1 , 2 :
10821114 output .append (3 )
10831115
1116+ @async_jump_test (1 , 3 , [], (ValueError , 'into' ))
1117+ async def test_no_jump_forwards_into_async_for_block (output ):
1118+ output .append (1 )
1119+ async for i in asynciter ([1 , 2 ]):
1120+ output .append (3 )
1121+
10841122 @jump_test (3 , 2 , [2 , 2 ], (ValueError , 'into' ))
10851123 def test_no_jump_backwards_into_for_block (output ):
10861124 for i in 1 , 2 :
10871125 output .append (2 )
10881126 output .append (3 )
10891127
1128+ @async_jump_test (3 , 2 , [2 , 2 ], (ValueError , 'into' ))
1129+ async def test_no_jump_backwards_into_async_for_block (output ):
1130+ async for i in asynciter ([1 , 2 ]):
1131+ output .append (2 )
1132+ output .append (3 )
1133+
10901134 @jump_test (1 , 3 , [], (ValueError , 'into' ))
10911135 def test_no_jump_forwards_into_with_block (output ):
10921136 output .append (1 )
@@ -1220,6 +1264,17 @@ def test_no_jump_into_for_block_before_else(output):
12201264 output .append (7 )
12211265 output .append (8 )
12221266
1267+ @async_jump_test (7 , 4 , [1 , 6 ], (ValueError , 'into' ))
1268+ async def test_no_jump_into_async_for_block_before_else (output ):
1269+ output .append (1 )
1270+ if not output : # always false
1271+ async for i in asynciter ([3 ]):
1272+ output .append (4 )
1273+ else :
1274+ output .append (6 )
1275+ output .append (7 )
1276+ output .append (8 )
1277+
12231278 def test_no_jump_to_non_integers (self ):
12241279 self .run_test (no_jump_to_non_integers , 2 , "Spam" , [True ])
12251280
0 commit comments