Implement PEP 380 - 'yield from' (closes #11682)
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index 8a101cf..3121eb1 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -231,7 +231,9 @@
"generators",
};
static PyTypeObject *Yield_type;
+_Py_IDENTIFIER(is_from);
static char *Yield_fields[]={
+ "is_from",
"value",
};
static PyTypeObject *Compare_type;
@@ -810,7 +812,7 @@
GeneratorExp_type = make_type("GeneratorExp", expr_type,
GeneratorExp_fields, 2);
if (!GeneratorExp_type) return 0;
- Yield_type = make_type("Yield", expr_type, Yield_fields, 1);
+ Yield_type = make_type("Yield", expr_type, Yield_fields, 2);
if (!Yield_type) return 0;
Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
if (!Compare_type) return 0;
@@ -1747,13 +1749,14 @@
}
expr_ty
-Yield(expr_ty value, int lineno, int col_offset, PyArena *arena)
+Yield(int is_from, expr_ty value, int lineno, int col_offset, PyArena *arena)
{
expr_ty p;
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
if (!p)
return NULL;
p->kind = Yield_kind;
+ p->v.Yield.is_from = is_from;
p->v.Yield.value = value;
p->lineno = lineno;
p->col_offset = col_offset;
@@ -2795,6 +2798,11 @@
case Yield_kind:
result = PyType_GenericNew(Yield_type, NULL, NULL);
if (!result) goto failed;
+ value = ast2obj_int(o->v.Yield.is_from);
+ if (!value) goto failed;
+ if (PyObject_SetAttrString(result, "is_from", value) == -1)
+ goto failed;
+ Py_DECREF(value);
value = ast2obj_expr(o->v.Yield.value);
if (!value) goto failed;
if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
@@ -5337,8 +5345,21 @@
return 1;
}
if (isinstance) {
+ int is_from;
expr_ty value;
+ if (_PyObject_HasAttrId(obj, &PyId_is_from)) {
+ int res;
+ tmp = _PyObject_GetAttrId(obj, &PyId_is_from);
+ if (tmp == NULL) goto failed;
+ res = obj2ast_int(tmp, &is_from, arena);
+ if (res != 0) goto failed;
+ Py_XDECREF(tmp);
+ tmp = NULL;
+ } else {
+ PyErr_SetString(PyExc_TypeError, "required field \"is_from\" missing from Yield");
+ return 1;
+ }
if (_PyObject_HasAttrId(obj, &PyId_value)) {
int res;
tmp = _PyObject_GetAttrId(obj, &PyId_value);
@@ -5350,7 +5371,7 @@
} else {
value = NULL;
}
- *out = Yield(value, lineno, col_offset, arena);
+ *out = Yield(is_from, value, lineno, col_offset, arena);
if (*out == NULL) goto failed;
return 0;
}
diff --git a/Python/ast.c b/Python/ast.c
index 110754b..7080c65 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -2369,13 +2369,24 @@
}
return ast_for_binop(c, n);
case yield_expr: {
+ node *an = NULL;
+ node *en = NULL;
+ int is_from = 0;
expr_ty exp = NULL;
- if (NCH(n) == 2) {
- exp = ast_for_testlist(c, CHILD(n, 1));
+ if (NCH(n) > 1)
+ an = CHILD(n, 1); /* yield_arg */
+ if (an) {
+ en = CHILD(an, NCH(an) - 1);
+ if (NCH(an) == 2) {
+ is_from = 1;
+ exp = ast_for_expr(c, en);
+ }
+ else
+ exp = ast_for_testlist(c, en);
if (!exp)
return NULL;
}
- return Yield(exp, LINENO(n), n->n_col_offset, c->c_arena);
+ return Yield(is_from, exp, LINENO(n), n->n_col_offset, c->c_arena);
}
case factor:
if (NCH(n) == 1) {
@@ -2399,7 +2410,7 @@
/*
arglist: (argument ',')* (argument [',']| '*' test [',' '**' test]
| '**' test)
- argument: [test '='] test [comp_for] # Really [keyword '='] test
+ argument: [test '='] (test) [comp_for] # Really [keyword '='] test
*/
int i, nargs, nkeywords, ngens;
@@ -2693,7 +2704,7 @@
continue_stmt: 'continue'
return_stmt: 'return' [testlist]
yield_stmt: yield_expr
- yield_expr: 'yield' testlist
+ yield_expr: 'yield' testlist | 'yield' 'from' test
raise_stmt: 'raise' [test [',' test [',' test]]]
*/
node *ch;
diff --git a/Python/ceval.c b/Python/ceval.c
index ed82b94..134d1ee 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1828,6 +1828,52 @@
why = WHY_RETURN;
goto fast_block_end;
+ TARGET(YIELD_FROM)
+ u = POP();
+ x = PyObject_GetIter(u);
+ Py_DECREF(u);
+ if (x == NULL)
+ break;
+ /* x is now the iterator, make the first next() call */
+ retval = (*Py_TYPE(x)->tp_iternext)(x);
+ if (!retval) {
+ /* iter may be exhausted */
+ Py_CLEAR(x);
+ if (!PyErr_ExceptionMatches(PyExc_StopIteration)) {
+ /* some other exception */
+ break;
+ }
+ /* try to get return value from exception */
+ PyObject *et, *ev, *tb;
+ PyErr_Fetch(&et, &ev, &tb);
+ Py_XDECREF(et);
+ Py_XDECREF(tb);
+ /* u is return value */
+ u = NULL;
+ if (ev) {
+ u = PyObject_GetAttrString(ev, "value");
+ Py_DECREF(ev);
+ if (u == NULL) {
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
+ /* some other exception */
+ break;
+ }
+ PyErr_Clear();
+ }
+ }
+ if (u == NULL) {
+ u = Py_None;
+ Py_INCREF(u);
+ }
+ PUSH(u);
+ continue;
+ }
+ /* x is iterator, retval is value to be yielded */
+ f->f_yieldfrom = x;
+ f->f_stacktop = stack_pointer;
+ why = WHY_YIELD;
+ goto fast_yield;
+
TARGET(YIELD_VALUE)
retval = POP();
f->f_stacktop = stack_pointer;
diff --git a/Python/compile.c b/Python/compile.c
index 849f487..4d91f50 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -840,6 +840,7 @@
case IMPORT_STAR:
return -1;
case YIELD_VALUE:
+ case YIELD_FROM:
return 0;
case POP_BLOCK:
@@ -3318,7 +3319,12 @@
else {
ADDOP_O(c, LOAD_CONST, Py_None, consts);
}
- ADDOP(c, YIELD_VALUE);
+ if (e->v.Yield.is_from) {
+ ADDOP(c, YIELD_FROM);
+ }
+ else {
+ ADDOP(c, YIELD_VALUE);
+ }
break;
case Compare_kind:
return compiler_compare(c, e);
diff --git a/Python/graminit.c b/Python/graminit.c
index a8af583..e91e09f 100644
--- a/Python/graminit.c
+++ b/Python/graminit.c
@@ -1791,7 +1791,7 @@
{167, 1},
};
static arc arcs_80_1[2] = {
- {9, 2},
+ {168, 2},
{0, 1},
};
static arc arcs_80_2[1] = {
@@ -1802,171 +1802,188 @@
{2, arcs_80_1},
{1, arcs_80_2},
};
-static dfa dfas[81] = {
- {256, "single_input", 0, 3, states_0,
- "\004\050\060\200\000\000\000\240\340\223\160\220\045\200\020\000\000\206\120\076\204"},
- {257, "file_input", 0, 2, states_1,
- "\204\050\060\200\000\000\000\240\340\223\160\220\045\200\020\000\000\206\120\076\204"},
- {258, "eval_input", 0, 3, states_2,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {259, "decorator", 0, 7, states_3,
- "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {260, "decorators", 0, 2, states_4,
- "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {261, "decorated", 0, 3, states_5,
- "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {262, "funcdef", 0, 8, states_6,
- "\000\000\020\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {263, "parameters", 0, 4, states_7,
- "\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {264, "typedargslist", 0, 18, states_8,
- "\000\000\040\200\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {265, "tfpdef", 0, 4, states_9,
- "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {266, "varargslist", 0, 18, states_10,
- "\000\000\040\200\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {267, "vfpdef", 0, 2, states_11,
- "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {268, "stmt", 0, 2, states_12,
- "\000\050\060\200\000\000\000\240\340\223\160\220\045\200\020\000\000\206\120\076\204"},
- {269, "simple_stmt", 0, 4, states_13,
- "\000\040\040\200\000\000\000\240\340\223\160\000\000\200\020\000\000\206\120\076\200"},
- {270, "small_stmt", 0, 2, states_14,
- "\000\040\040\200\000\000\000\240\340\223\160\000\000\200\020\000\000\206\120\076\200"},
- {271, "expr_stmt", 0, 6, states_15,
- "\000\040\040\200\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {272, "testlist_star_expr", 0, 3, states_16,
- "\000\040\040\200\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {273, "augassign", 0, 2, states_17,
- "\000\000\000\000\000\000\376\037\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {274, "del_stmt", 0, 3, states_18,
- "\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {275, "pass_stmt", 0, 2, states_19,
- "\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {276, "flow_stmt", 0, 2, states_20,
- "\000\000\000\000\000\000\000\000\340\001\000\000\000\000\000\000\000\000\000\000\200"},
- {277, "break_stmt", 0, 2, states_21,
- "\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000"},
- {278, "continue_stmt", 0, 2, states_22,
- "\000\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000"},
- {279, "return_stmt", 0, 3, states_23,
- "\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000"},
- {280, "yield_stmt", 0, 2, states_24,
- "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\200"},
- {281, "raise_stmt", 0, 5, states_25,
- "\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000"},
- {282, "import_stmt", 0, 2, states_26,
- "\000\000\000\000\000\000\000\000\000\022\000\000\000\000\000\000\000\000\000\000\000"},
- {283, "import_name", 0, 3, states_27,
- "\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000\000"},
- {284, "import_from", 0, 8, states_28,
- "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000"},
- {285, "import_as_name", 0, 4, states_29,
- "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {286, "dotted_as_name", 0, 4, states_30,
- "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {287, "import_as_names", 0, 3, states_31,
- "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {288, "dotted_as_names", 0, 2, states_32,
- "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {289, "dotted_name", 0, 2, states_33,
- "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {290, "global_stmt", 0, 3, states_34,
- "\000\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000"},
- {291, "nonlocal_stmt", 0, 3, states_35,
- "\000\000\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000\000\000"},
- {292, "assert_stmt", 0, 5, states_36,
- "\000\000\000\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000"},
- {293, "compound_stmt", 0, 2, states_37,
- "\000\010\020\000\000\000\000\000\000\000\000\220\045\000\000\000\000\000\000\000\004"},
- {294, "if_stmt", 0, 8, states_38,
- "\000\000\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000"},
- {295, "while_stmt", 0, 8, states_39,
- "\000\000\000\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\000"},
- {296, "for_stmt", 0, 10, states_40,
- "\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\000"},
- {297, "try_stmt", 0, 13, states_41,
- "\000\000\000\000\000\000\000\000\000\000\000\000\004\000\000\000\000\000\000\000\000"},
- {298, "with_stmt", 0, 5, states_42,
- "\000\000\000\000\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000"},
- {299, "with_item", 0, 4, states_43,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {300, "except_clause", 0, 5, states_44,
- "\000\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000"},
- {301, "suite", 0, 5, states_45,
- "\004\040\040\200\000\000\000\240\340\223\160\000\000\200\020\000\000\206\120\076\200"},
- {302, "test", 0, 6, states_46,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {303, "test_nocond", 0, 2, states_47,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {304, "lambdef", 0, 5, states_48,
- "\000\000\000\000\000\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000"},
- {305, "lambdef_nocond", 0, 5, states_49,
- "\000\000\000\000\000\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000"},
- {306, "or_test", 0, 2, states_50,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\020\000\000\206\120\076\000"},
- {307, "and_test", 0, 2, states_51,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\020\000\000\206\120\076\000"},
- {308, "not_test", 0, 3, states_52,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\020\000\000\206\120\076\000"},
- {309, "comparison", 0, 2, states_53,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
- {310, "comp_op", 0, 4, states_54,
- "\000\000\000\000\000\000\000\000\000\000\000\000\002\000\220\177\000\000\000\000\000"},
- {311, "star_expr", 0, 3, states_55,
- "\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {312, "expr", 0, 2, states_56,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
- {313, "xor_expr", 0, 2, states_57,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
- {314, "and_expr", 0, 2, states_58,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
- {315, "shift_expr", 0, 2, states_59,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
- {316, "arith_expr", 0, 2, states_60,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
- {317, "term", 0, 2, states_61,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
- {318, "factor", 0, 3, states_62,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
- {319, "power", 0, 4, states_63,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\120\076\000"},
- {320, "atom", 0, 9, states_64,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\120\076\000"},
- {321, "testlist_comp", 0, 5, states_65,
- "\000\040\040\200\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {322, "trailer", 0, 7, states_66,
- "\000\040\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\020\000\000"},
- {323, "subscriptlist", 0, 3, states_67,
- "\000\040\040\002\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {324, "subscript", 0, 5, states_68,
- "\000\040\040\002\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {325, "sliceop", 0, 3, states_69,
- "\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {326, "exprlist", 0, 3, states_70,
- "\000\040\040\200\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000"},
- {327, "testlist", 0, 3, states_71,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {328, "dictorsetmaker", 0, 11, states_72,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {329, "classdef", 0, 8, states_73,
- "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\004"},
- {330, "arglist", 0, 8, states_74,
- "\000\040\040\200\001\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {331, "argument", 0, 4, states_75,
- "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000"},
- {332, "comp_iter", 0, 2, states_76,
- "\000\000\000\000\000\000\000\000\000\000\000\020\001\000\000\000\000\000\000\000\000"},
- {333, "comp_for", 0, 6, states_77,
- "\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\000"},
- {334, "comp_if", 0, 4, states_78,
- "\000\000\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000"},
- {335, "encoding_decl", 0, 2, states_79,
- "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
- {336, "yield_expr", 0, 3, states_80,
- "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\200"},
+static arc arcs_81_0[2] = {
+ {73, 1},
+ {9, 2},
};
-static label labels[168] = {
+static arc arcs_81_1[1] = {
+ {24, 2},
+};
+static arc arcs_81_2[1] = {
+ {0, 2},
+};
+static state states_81[3] = {
+ {2, arcs_81_0},
+ {1, arcs_81_1},
+ {1, arcs_81_2},
+};
+static dfa dfas[82] = {
+ {256, "single_input", 0, 3, states_0,
+ "\004\050\060\200\000\000\000\240\340\223\160\220\045\200\020\000\000\206\120\076\204\000"},
+ {257, "file_input", 0, 2, states_1,
+ "\204\050\060\200\000\000\000\240\340\223\160\220\045\200\020\000\000\206\120\076\204\000"},
+ {258, "eval_input", 0, 3, states_2,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000\000"},
+ {259, "decorator", 0, 7, states_3,
+ "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {260, "decorators", 0, 2, states_4,
+ "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {261, "decorated", 0, 3, states_5,
+ "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {262, "funcdef", 0, 8, states_6,
+ "\000\000\020\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {263, "parameters", 0, 4, states_7,
+ "\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {264, "typedargslist", 0, 18, states_8,
+ "\000\000\040\200\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {265, "tfpdef", 0, 4, states_9,
+ "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {266, "varargslist", 0, 18, states_10,
+ "\000\000\040\200\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {267, "vfpdef", 0, 2, states_11,
+ "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {268, "stmt", 0, 2, states_12,
+ "\000\050\060\200\000\000\000\240\340\223\160\220\045\200\020\000\000\206\120\076\204\000"},
+ {269, "simple_stmt", 0, 4, states_13,
+ "\000\040\040\200\000\000\000\240\340\223\160\000\000\200\020\000\000\206\120\076\200\000"},
+ {270, "small_stmt", 0, 2, states_14,
+ "\000\040\040\200\000\000\000\240\340\223\160\000\000\200\020\000\000\206\120\076\200\000"},
+ {271, "expr_stmt", 0, 6, states_15,
+ "\000\040\040\200\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000\000"},
+ {272, "testlist_star_expr", 0, 3, states_16,
+ "\000\040\040\200\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000\000"},
+ {273, "augassign", 0, 2, states_17,
+ "\000\000\000\000\000\000\376\037\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {274, "del_stmt", 0, 3, states_18,
+ "\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {275, "pass_stmt", 0, 2, states_19,
+ "\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {276, "flow_stmt", 0, 2, states_20,
+ "\000\000\000\000\000\000\000\000\340\001\000\000\000\000\000\000\000\000\000\000\200\000"},
+ {277, "break_stmt", 0, 2, states_21,
+ "\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {278, "continue_stmt", 0, 2, states_22,
+ "\000\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {279, "return_stmt", 0, 3, states_23,
+ "\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {280, "yield_stmt", 0, 2, states_24,
+ "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\200\000"},
+ {281, "raise_stmt", 0, 5, states_25,
+ "\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {282, "import_stmt", 0, 2, states_26,
+ "\000\000\000\000\000\000\000\000\000\022\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {283, "import_name", 0, 3, states_27,
+ "\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {284, "import_from", 0, 8, states_28,
+ "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {285, "import_as_name", 0, 4, states_29,
+ "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {286, "dotted_as_name", 0, 4, states_30,
+ "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {287, "import_as_names", 0, 3, states_31,
+ "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {288, "dotted_as_names", 0, 2, states_32,
+ "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {289, "dotted_name", 0, 2, states_33,
+ "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {290, "global_stmt", 0, 3, states_34,
+ "\000\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000\000"},
+ {291, "nonlocal_stmt", 0, 3, states_35,
+ "\000\000\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000\000\000\000"},
+ {292, "assert_stmt", 0, 5, states_36,
+ "\000\000\000\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000"},
+ {293, "compound_stmt", 0, 2, states_37,
+ "\000\010\020\000\000\000\000\000\000\000\000\220\045\000\000\000\000\000\000\000\004\000"},
+ {294, "if_stmt", 0, 8, states_38,
+ "\000\000\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000"},
+ {295, "while_stmt", 0, 8, states_39,
+ "\000\000\000\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\000\000"},
+ {296, "for_stmt", 0, 10, states_40,
+ "\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000"},
+ {297, "try_stmt", 0, 13, states_41,
+ "\000\000\000\000\000\000\000\000\000\000\000\000\004\000\000\000\000\000\000\000\000\000"},
+ {298, "with_stmt", 0, 5, states_42,
+ "\000\000\000\000\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000\000"},
+ {299, "with_item", 0, 4, states_43,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000\000"},
+ {300, "except_clause", 0, 5, states_44,
+ "\000\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\000"},
+ {301, "suite", 0, 5, states_45,
+ "\004\040\040\200\000\000\000\240\340\223\160\000\000\200\020\000\000\206\120\076\200\000"},
+ {302, "test", 0, 6, states_46,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000\000"},
+ {303, "test_nocond", 0, 2, states_47,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000\000"},
+ {304, "lambdef", 0, 5, states_48,
+ "\000\000\000\000\000\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000"},
+ {305, "lambdef_nocond", 0, 5, states_49,
+ "\000\000\000\000\000\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000"},
+ {306, "or_test", 0, 2, states_50,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\020\000\000\206\120\076\000\000"},
+ {307, "and_test", 0, 2, states_51,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\020\000\000\206\120\076\000\000"},
+ {308, "not_test", 0, 3, states_52,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\020\000\000\206\120\076\000\000"},
+ {309, "comparison", 0, 2, states_53,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000\000"},
+ {310, "comp_op", 0, 4, states_54,
+ "\000\000\000\000\000\000\000\000\000\000\000\000\002\000\220\177\000\000\000\000\000\000"},
+ {311, "star_expr", 0, 3, states_55,
+ "\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {312, "expr", 0, 2, states_56,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000\000"},
+ {313, "xor_expr", 0, 2, states_57,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000\000"},
+ {314, "and_expr", 0, 2, states_58,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000\000"},
+ {315, "shift_expr", 0, 2, states_59,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000\000"},
+ {316, "arith_expr", 0, 2, states_60,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000\000"},
+ {317, "term", 0, 2, states_61,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000\000"},
+ {318, "factor", 0, 3, states_62,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000\000"},
+ {319, "power", 0, 4, states_63,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\120\076\000\000"},
+ {320, "atom", 0, 9, states_64,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\120\076\000\000"},
+ {321, "testlist_comp", 0, 5, states_65,
+ "\000\040\040\200\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000\000"},
+ {322, "trailer", 0, 7, states_66,
+ "\000\040\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\020\000\000\000"},
+ {323, "subscriptlist", 0, 3, states_67,
+ "\000\040\040\002\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000\000"},
+ {324, "subscript", 0, 5, states_68,
+ "\000\040\040\002\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000\000"},
+ {325, "sliceop", 0, 3, states_69,
+ "\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {326, "exprlist", 0, 3, states_70,
+ "\000\040\040\200\000\000\000\000\000\200\000\000\000\000\000\000\000\206\120\076\000\000"},
+ {327, "testlist", 0, 3, states_71,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000\000"},
+ {328, "dictorsetmaker", 0, 11, states_72,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000\000"},
+ {329, "classdef", 0, 8, states_73,
+ "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\004\000"},
+ {330, "arglist", 0, 8, states_74,
+ "\000\040\040\200\001\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000\000"},
+ {331, "argument", 0, 4, states_75,
+ "\000\040\040\000\000\000\000\000\000\200\000\000\000\200\020\000\000\206\120\076\000\000"},
+ {332, "comp_iter", 0, 2, states_76,
+ "\000\000\000\000\000\000\000\000\000\000\000\020\001\000\000\000\000\000\000\000\000\000"},
+ {333, "comp_for", 0, 6, states_77,
+ "\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000"},
+ {334, "comp_if", 0, 4, states_78,
+ "\000\000\000\000\000\000\000\000\000\000\000\020\000\000\000\000\000\000\000\000\000\000"},
+ {335, "encoding_decl", 0, 2, states_79,
+ "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
+ {336, "yield_expr", 0, 3, states_80,
+ "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\200\000"},
+ {337, "yield_arg", 0, 3, states_81,
+ "\000\040\040\000\000\000\000\000\000\202\000\000\000\200\020\000\000\206\120\076\000\000"},
+};
+static label labels[169] = {
{0, "EMPTY"},
{256, 0},
{4, 0},
@@ -2135,10 +2152,11 @@
{334, 0},
{335, 0},
{1, "yield"},
+ {337, 0},
};
grammar _PyParser_Grammar = {
- 81,
+ 82,
dfas,
- {168, labels},
+ {169, labels},
256
};
diff --git a/Python/opcode_targets.h b/Python/opcode_targets.h
index a91da79..2d6bcda 100644
--- a/Python/opcode_targets.h
+++ b/Python/opcode_targets.h
@@ -71,7 +71,7 @@
&&TARGET_STORE_LOCALS,
&&TARGET_PRINT_EXPR,
&&TARGET_LOAD_BUILD_CLASS,
- &&_unknown_opcode,
+ &&TARGET_YIELD_FROM,
&&_unknown_opcode,
&&_unknown_opcode,
&&TARGET_INPLACE_LSHIFT,
diff --git a/Python/symtable.c b/Python/symtable.c
index 824a53f..1ce7f70 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -19,10 +19,6 @@
#define IMPORT_STAR_WARNING "import * only allowed at module level"
-#define RETURN_VAL_IN_GENERATOR \
- "'return' with argument inside generator"
-
-
static PySTEntryObject *
ste_new(struct symtable *st, identifier name, _Py_block_ty block,
void *key, int lineno, int col_offset)
@@ -1133,14 +1129,6 @@
if (s->v.Return.value) {
VISIT(st, expr, s->v.Return.value);
st->st_cur->ste_returns_value = 1;
- if (st->st_cur->ste_generator) {
- PyErr_SetString(PyExc_SyntaxError,
- RETURN_VAL_IN_GENERATOR);
- PyErr_SyntaxLocationEx(st->st_filename,
- s->lineno,
- s->col_offset);
- return 0;
- }
}
break;
case Delete_kind:
@@ -1345,13 +1333,6 @@
if (e->v.Yield.value)
VISIT(st, expr, e->v.Yield.value);
st->st_cur->ste_generator = 1;
- if (st->st_cur->ste_returns_value) {
- PyErr_SetString(PyExc_SyntaxError,
- RETURN_VAL_IN_GENERATOR);
- PyErr_SyntaxLocationEx(st->st_filename,
- e->lineno, e->col_offset);
- return 0;
- }
break;
case Compare_kind:
VISIT(st, expr, e->v.Compare.left);