Message312081
In Python 2.6, a list comprehension was implemented in the current scope using a temporary _[1] variable to hold the list object:
>>> import dis
>>> dis.dis(compile('[x for x in y]', '?', 'exec'))
1 0 BUILD_LIST 0
3 DUP_TOP
4 STORE_NAME 0 (_[1])
7 LOAD_NAME 1 (y)
10 GET_ITER
>> 11 FOR_ITER 13 (to 27)
14 STORE_NAME 2 (x)
17 LOAD_NAME 0 (_[1])
20 LOAD_NAME 2 (x)
23 LIST_APPEND
24 JUMP_ABSOLUTE 11
>> 27 DELETE_NAME 0 (_[1])
30 POP_TOP
31 LOAD_CONST 0 (None)
34 RETURN_VALUE
Nick Cochlan moved comprehensions into a separate scope in #1660500, and removed the need for a temporary variable in the process (the list / dict / set lives only on the stack).
However, the symbol table generates the _[1] name:
>>> import symtable
>>> symtable.symtable('[x for x in y]', '?', 'exec').get_children()[0].get_symbols()
[<symbol '.0'>, <symbol '_[1]'>, <symbol 'x'>]
Can this be dropped? I think all temporary variable handling can be ripped out. |
|
Date |
User |
Action |
Args |
2018-02-12 21:33:51 | mjpieters | set | recipients:
+ mjpieters |
2018-02-12 21:33:51 | mjpieters | set | messageid: <1518471231.56.0.467229070634.issue32836@psf.upfronthosting.co.za> |
2018-02-12 21:33:51 | mjpieters | link | issue32836 messages |
2018-02-12 21:33:51 | mjpieters | create | |
|