Bugs item #1586448, was opened at 2006-10-28 22:58 Message generated for change (Comment added) made by gbrandl You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1586448&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Python Library Group: None >Status: Closed >Resolution: Fixed Priority: 5 Private: No Submitted By: sebastien Martini (seb_martini) >Assigned to: Georg Brandl (gbrandl) Summary: compiler module dont emit LIST_APPEND w/ list comprehension Initial Comment: In the module compiler, list comprehensions are implemented without emitting this bytecode. For example: >>> src = "[a for a in range(3)]" >>> co = compiler.compile(src, 'lc1', 'exec') >>> co <code object <module> at 0x404927b8, file "lc1", line 1> >>> dis.dis(co) 1 0 BUILD_LIST 0 3 DUP_TOP 4 LOAD_ATTR 0 (append) 7 STORE_NAME 1 ($append0) 10 LOAD_NAME 2 (range) 13 LOAD_CONST 1 (3) 16 CALL_FUNCTION 1 19 GET_ITER >> 20 FOR_ITER 16 (to 39) 23 STORE_NAME 3 (a) 26 LOAD_NAME 1 ($append0) 29 LOAD_NAME 3 (a) 32 CALL_FUNCTION 1 35 POP_TOP 36 JUMP_ABSOLUTE 20 >> 39 DELETE_NAME 1 ($append0) 42 POP_TOP 43 LOAD_CONST 0 (None) 46 RETURN_VALUE >>> co2 = compile(src, 'lc2', 'exec') >>> co2 <code object <module> at 0x40492770, file "lc2", line 1> >>> dis.dis(co2) 1 0 BUILD_LIST 0 3 DUP_TOP 4 STORE_NAME 0 (_[1]) 7 LOAD_NAME 1 (range) 10 LOAD_CONST 0 (3) 13 CALL_FUNCTION 1 16 GET_ITER >> 17 FOR_ITER 13 (to 33) 20 STORE_NAME 2 (a) 23 LOAD_NAME 0 (_[1]) 26 LOAD_NAME 2 (a) 29 LIST_APPEND 30 JUMP_ABSOLUTE 17 >> 33 DELETE_NAME 0 (_[1]) 36 POP_TOP 37 LOAD_CONST 1 (None) 40 RETURN_VALUE -- sébastien martini ---------------------------------------------------------------------- >Comment By: Georg Brandl (gbrandl) Date: 2006-10-29 08:54 Message: Logged In: YES user_id=849994 I "fixed" this in rev. 52520, now the compiler module generates the same bytecode for listcomps as the builtin compiler. Not backporting this, as it isn't really a bug. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1586448&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com