aboutsummaryrefslogtreecommitdiff
path: root/Python/symtable.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-02-04 10:53:48 +0200
committerGitHub <noreply@github.com>2018-02-04 10:53:48 +0200
commit07ca9afaa8768b44baf816b4998d209ed3e0088f (patch)
treeacb09f5cd6a660acb41d77c150cdd6236bf02d96 /Python/symtable.c
parent8b5fa289fdb04b6b919cf95fa99246aa872e47a8 (diff)
downloadcpython3-07ca9afaa8768b44baf816b4998d209ed3e0088f.tar.gz
bpo-10544: Disallow "yield" in comprehensions and generator expressions. (GH-4564)
Diffstat (limited to 'Python/symtable.c')
-rw-r--r--Python/symtable.c31
1 files changed, 7 insertions, 24 deletions
diff --git a/Python/symtable.c b/Python/symtable.c
index bbac25cf37..ac14058fef 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -1754,35 +1754,18 @@ symtable_handle_comprehension(struct symtable *st, expr_ty e,
VISIT(st, expr, value);
VISIT(st, expr, elt);
if (st->st_cur->ste_generator) {
- PyObject *msg = PyUnicode_FromString(
+ PyErr_SetString(PyExc_SyntaxError,
(e->kind == ListComp_kind) ? "'yield' inside list comprehension" :
(e->kind == SetComp_kind) ? "'yield' inside set comprehension" :
(e->kind == DictComp_kind) ? "'yield' inside dict comprehension" :
"'yield' inside generator expression");
- if (msg == NULL) {
- symtable_exit_block(st, (void *)e);
- return 0;
- }
- if (PyErr_WarnExplicitObject(PyExc_DeprecationWarning,
- msg, st->st_filename, st->st_cur->ste_lineno,
- NULL, NULL) == -1)
- {
- if (PyErr_ExceptionMatches(PyExc_DeprecationWarning)) {
- /* Replace the DeprecationWarning exception with a SyntaxError
- to get a more accurate error report */
- PyErr_Clear();
- PyErr_SetObject(PyExc_SyntaxError, msg);
- PyErr_SyntaxLocationObject(st->st_filename,
- st->st_cur->ste_lineno,
- st->st_cur->ste_col_offset);
- }
- Py_DECREF(msg);
- symtable_exit_block(st, (void *)e);
- return 0;
- }
- Py_DECREF(msg);
+ PyErr_SyntaxLocationObject(st->st_filename,
+ st->st_cur->ste_lineno,
+ st->st_cur->ste_col_offset);
+ symtable_exit_block(st, (void *)e);
+ return 0;
}
- st->st_cur->ste_generator |= is_generator;
+ st->st_cur->ste_generator = is_generator;
return symtable_exit_block(st, (void *)e);
}