File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -943,10 +943,20 @@ def return_genexp():
943
943
genexp_lines = [None , 1 , 3 , 1 ]
944
944
945
945
genexp_code = return_genexp .__code__ .co_consts [1 ]
946
- code_lines = [None if line is None else line - return_genexp .__code__ .co_firstlineno
946
+ code_lines = [ None if line is None else line - return_genexp .__code__ .co_firstlineno
947
947
for (_ , _ , line ) in genexp_code .co_lines () ]
948
948
self .assertEqual (genexp_lines , code_lines )
949
949
950
+ def test_line_number_implicit_return_after_async_for (self ):
951
+
952
+ async def test (aseq ):
953
+ async for i in aseq :
954
+ body
955
+
956
+ expected_lines = [None , 1 , 2 , 1 ]
957
+ code_lines = [ None if line is None else line - test .__code__ .co_firstlineno
958
+ for (_ , _ , line ) in test .__code__ .co_lines () ]
959
+ self .assertEqual (expected_lines , code_lines )
950
960
951
961
def test_big_dict_literal (self ):
952
962
# The compiler has a flushing point in "compiler_dict" that calls compiles
Original file line number Diff line number Diff line change @@ -3002,7 +3002,9 @@ compiler_async_for(struct compiler *c, stmt_ty s)
3002
3002
/* Except block for __anext__ */
3003
3003
compiler_use_next_block (c , except );
3004
3004
3005
- UNSET_LOC (c );
3005
+ /* Use same line number as the iterator,
3006
+ * as the END_ASYNC_FOR succeeds the `for`, not the body. */
3007
+ SET_LOC (c , s -> v .AsyncFor .iter );
3006
3008
ADDOP (c , END_ASYNC_FOR );
3007
3009
3008
3010
/* `else` block */
You can’t perform that action at this time.
0 commit comments