Created on 2018-02-12 21:33 by mjpieters, last changed 2018-08-27 09:55 by serhiy.storchaka. This issue is now closed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 5680 | merged | nitishch, 2018-02-14 07:31 | |
| PR 5913 | merged | miss-islington, 2018-02-26 21:32 | |
| Messages (4) | |||
|---|---|---|---|
| msg312081 - (view) | Author: Martijn Pieters (mjpieters) * | Date: 2018-02-12 21:33 | |
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.
|
|||
| msg312155 - (view) | Author: Nick Coghlan (ncoghlan) * | Date: 2018-02-14 04:35 | |
We still need to the ".0" style temporary variables that are used for argument names in the implicitly generated functions, but it's definitely plausible that we're not actually using the "_[1]" style hidden variables anywhere anymore. |
|||
| msg312959 - (view) | Author: Nick Coghlan (ncoghlan) * | Date: 2018-02-26 21:31 | |
New changeset 3a087beddd9f0955eb9080a6fd1499ff89ca74bf by Nick Coghlan (Nitish Chandra) in branch 'master': bpo-32836: Remove obsolete code from symtable pass (GH-5680) https://github.com/python/cpython/commit/3a087beddd9f0955eb9080a6fd1499ff89ca74bf |
|||
| msg313565 - (view) | Author: miss-islington (miss-islington) | Date: 2018-03-10 23:11 | |
New changeset 5506d603021518eaaa89e7037905f7a698c5e95c by Miss Islington (bot) in branch '3.7': bpo-32836: Remove obsolete code from symtable pass (GH-5680) https://github.com/python/cpython/commit/5506d603021518eaaa89e7037905f7a698c5e95c |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2018-08-27 09:55:02 | serhiy.storchaka | set | status: open -> closed stage: patch review -> resolved versions: + Python 3.7, Python 3.8 |
| 2018-03-10 23:11:49 | miss-islington | set | nosy:
+ miss-islington messages: + msg313565 |
| 2018-02-26 21:32:48 | miss-islington | set | pull_requests: + pull_request5684 |
| 2018-02-26 21:31:27 | ncoghlan | set | messages: + msg312959 |
| 2018-02-14 07:31:39 | nitishch | set | keywords:
+ patch stage: patch review pull_requests: + pull_request5476 |
| 2018-02-14 04:35:44 | ncoghlan | set | type: behavior messages: + msg312155 |
| 2018-02-13 09:18:35 | serhiy.storchaka | set | nosy:
+ ncoghlan |
| 2018-02-13 07:35:21 | nitishch | set | nosy:
+ nitishch |
| 2018-02-12 21:33:51 | mjpieters | create | |