Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(27138)

Unified Diff: Python/Python-ast.c

Issue 11682: PEP 380 reference implementation for 3.3
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
--- a/Python/Python-ast.c Thu Jan 12 08:06:49 2012 +0100
+++ b/Python/Python-ast.c Fri Jan 13 00:26:31 2012 +1000
@@ -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;
}
« Objects/exceptions.c ('K') | « Python/opcode_targets.h ('k') | Python/symtable.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+