@@ -4411,7 +4411,6 @@ codegen_sync_comprehension_generator(compiler *c, location loc,
44114411
44124412 comprehension_ty gen = (comprehension_ty )asdl_seq_GET (generators ,
44134413 gen_index );
4414- int is_outer_genexpr = gen_index == 0 && type == COMP_GENEXP ;
44154414 if (!iter_on_stack ) {
44164415 if (gen_index == 0 ) {
44174416 assert (METADATA (c )-> u_argcount == 1 );
@@ -4442,15 +4441,13 @@ codegen_sync_comprehension_generator(compiler *c, location loc,
44424441 }
44434442 if (IS_JUMP_TARGET_LABEL (start )) {
44444443 VISIT (c , expr , gen -> iter );
4444+ ADDOP (c , LOC (gen -> iter ), GET_ITER );
44454445 }
44464446 }
44474447 }
44484448
44494449 if (IS_JUMP_TARGET_LABEL (start )) {
44504450 depth ++ ;
4451- if (!is_outer_genexpr ) {
4452- ADDOP (c , LOC (gen -> iter ), GET_ITER );
4453- }
44544451 USE_LABEL (c , start );
44554452 ADDOP_JUMP (c , LOC (gen -> iter ), FOR_ITER , anchor );
44564453 }
@@ -4544,9 +4541,9 @@ codegen_async_comprehension_generator(compiler *c, location loc,
45444541 else {
45454542 /* Sub-iter - calculate on the fly */
45464543 VISIT (c , expr , gen -> iter );
4544+ ADDOP (c , LOC (gen -> iter ), GET_AITER );
45474545 }
45484546 }
4549- ADDOP (c , LOC (gen -> iter ), GET_AITER );
45504547
45514548 USE_LABEL (c , start );
45524549 /* Runtime will push a block here, so we need to account for that */
@@ -4758,6 +4755,19 @@ pop_inlined_comprehension_state(compiler *c, location loc,
47584755 return SUCCESS ;
47594756}
47604757
4758+ static inline int
4759+ codegen_comprehension_iter (compiler * c , comprehension_ty comp )
4760+ {
4761+ VISIT (c , expr , comp -> iter );
4762+ if (comp -> is_async ) {
4763+ ADDOP (c , LOC (comp -> iter ), GET_AITER );
4764+ }
4765+ else {
4766+ ADDOP (c , LOC (comp -> iter ), GET_ITER );
4767+ }
4768+ return SUCCESS ;
4769+ }
4770+
47614771static int
47624772codegen_comprehension (compiler * c , expr_ty e , int type ,
47634773 identifier name , asdl_comprehension_seq * generators , expr_ty elt ,
@@ -4776,9 +4786,10 @@ codegen_comprehension(compiler *c, expr_ty e, int type,
47764786 location loc = LOC (e );
47774787
47784788 outermost = (comprehension_ty ) asdl_seq_GET (generators , 0 );
4779- int is_sync_genexpr = type == COMP_GENEXP && !outermost -> is_async ;
47804789 if (is_inlined ) {
4781- VISIT (c , expr , outermost -> iter );
4790+ if (codegen_comprehension_iter (c , outermost )) {
4791+ goto error ;
4792+ }
47824793 if (push_inlined_comprehension_state (c , loc , entry , & inline_state )) {
47834794 goto error ;
47844795 }
@@ -4852,10 +4863,10 @@ codegen_comprehension(compiler *c, expr_ty e, int type,
48524863 }
48534864 Py_CLEAR (co );
48544865
4855- VISIT (c , expr , outermost -> iter );
4856- if (is_sync_genexpr ) {
4857- ADDOP (c , loc , GET_ITER );
4866+ if (codegen_comprehension_iter (c , outermost )) {
4867+ goto error ;
48584868 }
4869+
48594870 ADDOP_I (c , loc , CALL , 0 );
48604871
48614872 if (is_async_comprehension && type != COMP_GENEXP ) {
0 commit comments