From 07ca9afaa8768b44baf816b4998d209ed3e0088f Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 4 Feb 2018 10:53:48 +0200 Subject: bpo-10544: Disallow "yield" in comprehensions and generator expressions. (GH-4564) --- Python/symtable.c | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) (limited to 'Python/symtable.c') 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); } -- cgit v1.2.3