diff options
author | Christian Heimes <christian@cheimes.de> | 2008-02-23 15:01:05 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2008-02-23 15:01:05 (GMT) |
commit | 5224d28d38eb784f17c2fed3f48368285df6d17a (patch) | |
tree | b258202efc39ae5239d91dcf5b1898c6ce713f16 /Python/Python-ast.c | |
parent | b12f0b581a6f268d0611c87012d1273aeca220b8 (diff) | |
download | cpython-5224d28d38eb784f17c2fed3f48368285df6d17a.zip cpython-5224d28d38eb784f17c2fed3f48368285df6d17a.tar.gz cpython-5224d28d38eb784f17c2fed3f48368285df6d17a.tar.bz2 |
Patch #1759: Backport of PEP 3129 class decorators
with some help from Georg
Diffstat (limited to 'Python/Python-ast.c')
-rw-r--r-- | Python/Python-ast.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 421a2d1..8d51a0d 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -42,13 +42,14 @@ static char *FunctionDef_fields[]={ "name", "args", "body", - "decorators", + "decorator_list", }; static PyTypeObject *ClassDef_type; static char *ClassDef_fields[]={ "name", "bases", "body", + "decorator_list", }; static PyTypeObject *Return_type; static char *Return_fields[]={ @@ -469,7 +470,7 @@ static int init_types(void) FunctionDef_type = make_type("FunctionDef", stmt_type, FunctionDef_fields, 4); if (!FunctionDef_type) return 0; - ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 3); + ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 4); if (!ClassDef_type) return 0; Return_type = make_type("Return", stmt_type, Return_fields, 1); if (!Return_type) return 0; @@ -790,7 +791,7 @@ Suite(asdl_seq * body, PyArena *arena) stmt_ty FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * - decorators, int lineno, int col_offset, PyArena *arena) + decorator_list, int lineno, int col_offset, PyArena *arena) { stmt_ty p; if (!name) { @@ -810,15 +811,15 @@ FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * p->v.FunctionDef.name = name; p->v.FunctionDef.args = args; p->v.FunctionDef.body = body; - p->v.FunctionDef.decorators = decorators; + p->v.FunctionDef.decorator_list = decorator_list; p->lineno = lineno; p->col_offset = col_offset; return p; } stmt_ty -ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno, int - col_offset, PyArena *arena) +ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, asdl_seq * + decorator_list, int lineno, int col_offset, PyArena *arena) { stmt_ty p; if (!name) { @@ -833,6 +834,7 @@ ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno, int p->v.ClassDef.name = name; p->v.ClassDef.bases = bases; p->v.ClassDef.body = body; + p->v.ClassDef.decorator_list = decorator_list; p->lineno = lineno; p->col_offset = col_offset; return p; @@ -1906,9 +1908,11 @@ ast2obj_stmt(void* _o) if (PyObject_SetAttrString(result, "body", value) == -1) goto failed; Py_DECREF(value); - value = ast2obj_list(o->v.FunctionDef.decorators, ast2obj_expr); + value = ast2obj_list(o->v.FunctionDef.decorator_list, + ast2obj_expr); if (!value) goto failed; - if (PyObject_SetAttrString(result, "decorators", value) == -1) + if (PyObject_SetAttrString(result, "decorator_list", value) == + -1) goto failed; Py_DECREF(value); break; @@ -1930,6 +1934,13 @@ ast2obj_stmt(void* _o) if (PyObject_SetAttrString(result, "body", value) == -1) goto failed; Py_DECREF(value); + value = ast2obj_list(o->v.ClassDef.decorator_list, + ast2obj_expr); + if (!value) goto failed; + if (PyObject_SetAttrString(result, "decorator_list", value) == + -1) + goto failed; + Py_DECREF(value); break; case Return_kind: result = PyType_GenericNew(Return_type, NULL, NULL); |