New submission from Martijn Pieters <m...@python.org>:

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.

----------
messages: 312081
nosy: mjpieters
priority: normal
severity: normal
status: open
title: Symbol table for comprehensions (list, dict, set) still includes 
temporary _[1] variable

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32836>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to