[Python-checkins] bpo-32836: Remove obsolete code from symtable pass (GH-5680)
Nick Coghlan
webhook-mailer at python.org
Mon Feb 26 16:31:28 EST 2018
https://github.com/python/cpython/commit/3a087beddd9f0955eb9080a6fd1499ff89ca74bf
commit: 3a087beddd9f0955eb9080a6fd1499ff89ca74bf
branch: master
author: Nitish Chandra <nitishchandrachinta at gmail.com>
committer: Nick Coghlan <ncoghlan at gmail.com>
date: 2018-02-27T07:31:20+10:00
summary:
bpo-32836: Remove obsolete code from symtable pass (GH-5680)
When comprehensions switched to using a nested scope, the old
code for generating a temporary name to hold the accumulation
target became redundant, but was never actually removed.
Patch by Nitish Chandra.
files:
A Misc/NEWS.d/next/Core and Builtins/2018-02-14-12-35-47.bpo-32836.bThJnx.rst
M Include/symtable.h
M Python/symtable.c
diff --git a/Include/symtable.h b/Include/symtable.h
index 86ae3c28e878..007f88db40e7 100644
--- a/Include/symtable.h
+++ b/Include/symtable.h
@@ -60,7 +60,6 @@ typedef struct _symtable_entry {
int ste_col_offset; /* offset of first line of block */
int ste_opt_lineno; /* lineno of last exec or import * */
int ste_opt_col_offset; /* offset of last exec or import * */
- int ste_tmpname; /* counter for listcomp temp vars */
struct symtable *ste_table;
} PySTEntryObject;
diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-02-14-12-35-47.bpo-32836.bThJnx.rst b/Misc/NEWS.d/next/Core and Builtins/2018-02-14-12-35-47.bpo-32836.bThJnx.rst
new file mode 100644
index 000000000000..4eeb9aa2e52c
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2018-02-14-12-35-47.bpo-32836.bThJnx.rst
@@ -0,0 +1 @@
+Don't use temporary variables in cases of list/dict/set comprehensions
diff --git a/Python/symtable.c b/Python/symtable.c
index ac14058fefd2..3e8c6f5dae30 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -69,7 +69,6 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,
ste->ste_varkeywords = 0;
ste->ste_opt_lineno = 0;
ste->ste_opt_col_offset = 0;
- ste->ste_tmpname = 0;
ste->ste_lineno = lineno;
ste->ste_col_offset = col_offset;
@@ -1082,24 +1081,6 @@ symtable_add_def(struct symtable *st, PyObject *name, int flag)
} \
}
-static int
-symtable_new_tmpname(struct symtable *st)
-{
- char tmpname[256];
- identifier tmp;
-
- PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]",
- ++st->st_cur->ste_tmpname);
- tmp = PyUnicode_InternFromString(tmpname);
- if (!tmp)
- return 0;
- if (!symtable_add_def(st, tmp, DEF_LOCAL))
- return 0;
- Py_DECREF(tmp);
- return 1;
-}
-
-
static int
symtable_record_directive(struct symtable *st, identifier name, stmt_ty s)
{
@@ -1723,7 +1704,6 @@ symtable_handle_comprehension(struct symtable *st, expr_ty e,
expr_ty elt, expr_ty value)
{
int is_generator = (e->kind == GeneratorExp_kind);
- int needs_tmp = !is_generator;
comprehension_ty outermost = ((comprehension_ty)
asdl_seq_GET(generators, 0));
/* Outermost iterator is evaluated in current scope */
@@ -1742,11 +1722,6 @@ symtable_handle_comprehension(struct symtable *st, expr_ty e,
symtable_exit_block(st, (void *)e);
return 0;
}
- /* Allocate temporary name if needed */
- if (needs_tmp && !symtable_new_tmpname(st)) {
- symtable_exit_block(st, (void *)e);
- return 0;
- }
VISIT(st, expr, outermost->target);
VISIT_SEQ(st, expr, outermost->ifs);
VISIT_SEQ_TAIL(st, comprehension, generators, 1);
More information about the Python-checkins
mailing list