diff options
author | Mark Dickinson <mdickinson@enthought.com> | 2012-11-25 14:37:43 (GMT) |
---|---|---|
committer | Mark Dickinson <mdickinson@enthought.com> | 2012-11-25 14:37:43 (GMT) |
commit | 073f0673697380a00dc2067ab3a999354893df51 (patch) | |
tree | ea7fc1d821d1aeaf0d8f7ca68ac22545ab63925f /Python | |
parent | ab56710989745ff11c10205ea993c2e423c22f75 (diff) | |
parent | ded35aeb9d5ae1671174f10c0ae8a7166693b17c (diff) | |
download | cpython-073f0673697380a00dc2067ab3a999354893df51.zip cpython-073f0673697380a00dc2067ab3a999354893df51.tar.gz cpython-073f0673697380a00dc2067ab3a999354893df51.tar.bz2 |
Issue #16546: merge fix from 3.3
Diffstat (limited to 'Python')
-rw-r--r-- | Python/Python-ast.c | 8 | ||||
-rw-r--r-- | Python/ast.c | 3 | ||||
-rw-r--r-- | Python/compile.c | 25 | ||||
-rw-r--r-- | Python/symtable.c | 12 |
4 files changed, 25 insertions, 23 deletions
diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 805f2b8..e6f1e58 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -1802,6 +1802,11 @@ expr_ty YieldFrom(expr_ty value, int lineno, int col_offset, PyArena *arena) { expr_ty p; + if (!value) { + PyErr_SetString(PyExc_ValueError, + "field value is required for YieldFrom"); + return NULL; + } p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); if (!p) return NULL; @@ -5431,7 +5436,8 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) Py_XDECREF(tmp); tmp = NULL; } else { - value = NULL; + PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); + return 1; } *out = YieldFrom(value, lineno, col_offset, arena); if (*out == NULL) goto failed; diff --git a/Python/ast.c b/Python/ast.c index 0c0c1a6..7657b22 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -224,8 +224,7 @@ validate_expr(expr_ty exp, expr_context_ty ctx) case Yield_kind: return !exp->v.Yield.value || validate_expr(exp->v.Yield.value, Load); case YieldFrom_kind: - return !exp->v.YieldFrom.value || - validate_expr(exp->v.YieldFrom.value, Load); + return validate_expr(exp->v.YieldFrom.value, Load); case Compare_kind: if (!asdl_seq_LEN(exp->v.Compare.comparators)) { PyErr_SetString(PyExc_ValueError, "Compare with no comparators"); diff --git a/Python/compile.c b/Python/compile.c index 5016f99..3cf71ef 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -3341,27 +3341,24 @@ compiler_visit_expr(struct compiler *c, expr_ty e) case DictComp_kind: return compiler_dictcomp(c, e); case Yield_kind: - case YieldFrom_kind: { - expr_ty value; if (c->u->u_ste->ste_type != FunctionBlock) return compiler_error(c, "'yield' outside function"); - value = (e->kind == YieldFrom_kind) ? e->v.YieldFrom.value : e->v.Yield.value; - if (value) { - VISIT(c, expr, value); + if (e->v.Yield.value) { + VISIT(c, expr, e->v.Yield.value); } else { ADDOP_O(c, LOAD_CONST, Py_None, consts); } - if (e->kind == YieldFrom_kind) { - ADDOP(c, GET_ITER); - ADDOP_O(c, LOAD_CONST, Py_None, consts); - ADDOP(c, YIELD_FROM); - } - else { - ADDOP(c, YIELD_VALUE); - } + ADDOP(c, YIELD_VALUE); + break; + case YieldFrom_kind: + if (c->u->u_ste->ste_type != FunctionBlock) + return compiler_error(c, "'yield' outside function"); + VISIT(c, expr, e->v.YieldFrom.value); + ADDOP(c, GET_ITER); + ADDOP_O(c, LOAD_CONST, Py_None, consts); + ADDOP(c, YIELD_FROM); break; - } case Compare_kind: return compiler_compare(c, e); case Call_kind: diff --git a/Python/symtable.c b/Python/symtable.c index da2c1e3..8d941f0 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -1412,14 +1412,14 @@ symtable_visit_expr(struct symtable *st, expr_ty e) VISIT_QUIT(st, 0); break; case Yield_kind: - case YieldFrom_kind: { - expr_ty value; - value = (e->kind == YieldFrom_kind) ? e->v.YieldFrom.value : e->v.Yield.value; - if (value) - VISIT(st, expr, value); + if (e->v.Yield.value) + VISIT(st, expr, e->v.Yield.value); + st->st_cur->ste_generator = 1; + break; + case YieldFrom_kind: + VISIT(st, expr, e->v.YieldFrom.value); st->st_cur->ste_generator = 1; break; - } case Compare_kind: VISIT(st, expr, e->v.Compare.left); VISIT_SEQ(st, expr, e->v.Compare.comparators); |