diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py index 7e125ef..312075d 100644 --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -147,22 +147,21 @@ def bug1333982(x=[]): dis_bug1333982 = """\ %3d 0 LOAD_CONST 1 (0) - 2 POP_JUMP_IF_TRUE 26 + 2 POP_JUMP_IF_TRUE 24 4 LOAD_GLOBAL 0 (AssertionError) 6 LOAD_CONST 2 ( at 0x..., file "%s", line %d>) 8 LOAD_CONST 3 ('bug1333982..') 10 MAKE_FUNCTION 0 12 LOAD_FAST 0 (x) - 14 GET_ITER - 16 CALL_FUNCTION 1 (1 positional, 0 keyword pair) + 14 CALL_FUNCTION 1 (1 positional, 0 keyword pair) -%3d 18 LOAD_CONST 4 (1) - 20 BINARY_ADD - 22 CALL_FUNCTION 1 (1 positional, 0 keyword pair) - 24 RAISE_VARARGS 1 +%3d 16 LOAD_CONST 4 (1) + 18 BINARY_ADD + 20 CALL_FUNCTION 1 (1 positional, 0 keyword pair) + 22 RAISE_VARARGS 1 -%3d >> 26 LOAD_CONST 0 (None) - 28 RETURN_VALUE +%3d >> 24 LOAD_CONST 0 (None) + 26 RETURN_VALUE """ % (bug1333982.__code__.co_firstlineno + 1, __file__, bug1333982.__code__.co_firstlineno + 1, diff --git a/Python/compile.c b/Python/compile.c index ffde903..41c884c 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -3432,6 +3432,8 @@ compiler_comprehension_generator(struct compiler *c, else { /* Sub-iter - calculate on the fly */ VISIT(c, expr, gen->iter); + } + if (gen_index != 0 || type != COMP_GENEXP) { ADDOP(c, GET_ITER); } compiler_use_next_block(c, start); @@ -3549,7 +3551,9 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type, Py_DECREF(co); VISIT(c, expr, outermost_iter); - ADDOP(c, GET_ITER); + if (type == COMP_GENEXP) { + ADDOP(c, GET_ITER); + } ADDOP_I(c, CALL_FUNCTION, 1); return 1; error_in_scope: