Skip to content

Commit 5506d60

Browse files
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. (cherry picked from commit 3a087be) Co-authored-by: Nitish Chandra <[email protected]>
1 parent e8a5a92 commit 5506d60

File tree

3 files changed

+1
-26
lines changed

3 files changed

+1
-26
lines changed

Include/symtable.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ typedef struct _symtable_entry {
6060
int ste_col_offset; /* offset of first line of block */
6161
int ste_opt_lineno; /* lineno of last exec or import * */
6262
int ste_opt_col_offset; /* offset of last exec or import * */
63-
int ste_tmpname; /* counter for listcomp temp vars */
6463
struct symtable *ste_table;
6564
} PySTEntryObject;
6665

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Don't use temporary variables in cases of list/dict/set comprehensions

Python/symtable.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ ste_new(struct symtable *st, identifier name, _Py_block_ty block,
6969
ste->ste_varkeywords = 0;
7070
ste->ste_opt_lineno = 0;
7171
ste->ste_opt_col_offset = 0;
72-
ste->ste_tmpname = 0;
7372
ste->ste_lineno = lineno;
7473
ste->ste_col_offset = col_offset;
7574

@@ -1082,24 +1081,6 @@ symtable_add_def(struct symtable *st, PyObject *name, int flag)
10821081
} \
10831082
}
10841083

1085-
static int
1086-
symtable_new_tmpname(struct symtable *st)
1087-
{
1088-
char tmpname[256];
1089-
identifier tmp;
1090-
1091-
PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]",
1092-
++st->st_cur->ste_tmpname);
1093-
tmp = PyUnicode_InternFromString(tmpname);
1094-
if (!tmp)
1095-
return 0;
1096-
if (!symtable_add_def(st, tmp, DEF_LOCAL))
1097-
return 0;
1098-
Py_DECREF(tmp);
1099-
return 1;
1100-
}
1101-
1102-
11031084
static int
11041085
symtable_record_directive(struct symtable *st, identifier name, stmt_ty s)
11051086
{
@@ -1723,7 +1704,6 @@ symtable_handle_comprehension(struct symtable *st, expr_ty e,
17231704
expr_ty elt, expr_ty value)
17241705
{
17251706
int is_generator = (e->kind == GeneratorExp_kind);
1726-
int needs_tmp = !is_generator;
17271707
comprehension_ty outermost = ((comprehension_ty)
17281708
asdl_seq_GET(generators, 0));
17291709
/* Outermost iterator is evaluated in current scope */
@@ -1742,11 +1722,6 @@ symtable_handle_comprehension(struct symtable *st, expr_ty e,
17421722
symtable_exit_block(st, (void *)e);
17431723
return 0;
17441724
}
1745-
/* Allocate temporary name if needed */
1746-
if (needs_tmp && !symtable_new_tmpname(st)) {
1747-
symtable_exit_block(st, (void *)e);
1748-
return 0;
1749-
}
17501725
VISIT(st, expr, outermost->target);
17511726
VISIT_SEQ(st, expr, outermost->ifs);
17521727
VISIT_SEQ_TAIL(st, comprehension, generators, 1);

0 commit comments

Comments
 (0)