[ python-Bugs-1586448 ] compiler module dont emit LIST_APPEND w/ list comprehension
SourceForge.net
noreply at sourceforge.net
Sun Oct 29 00:58:33 CEST 2006
Bugs item #1586448, was opened at 2006-10-29 00:58
Message generated for change (Tracker Item Submitted) made by Item Submitter
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: Open
Resolution: None
Priority: 5
Private: No
Submitted By: sebastien Martini (seb_martini)
Assigned to: Nobody/Anonymous (nobody)
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
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1586448&group_id=5470
More information about the Python-bugs-list
mailing list