summaryrefslogtreecommitdiff
path: root/Python/Python-ast.c
diff options
context:
space:
mode:
authorArmin Ronacher <armin.ronacher@active-4.com>2008-10-19 08:27:43 +0000
committerArmin Ronacher <armin.ronacher@active-4.com>2008-10-19 08:27:43 +0000
commit51b115bb9907f25db2d40cbe69cdebd8f45b8466 (patch)
treede546f523e2e21e2f51e567728dd3f69524a140a /Python/Python-ast.c
parentf1deaddfe66b1f6f4ee94fc28c96e5ec3ab06782 (diff)
downloadcpython-51b115bb9907f25db2d40cbe69cdebd8f45b8466.tar.gz
Fixed #4067 by implementing _attributes and _fields for the AST root node.
Diffstat (limited to 'Python/Python-ast.c')
-rw-r--r--Python/Python-ast.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index 1c78515bce..cabc66639b 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -615,11 +615,29 @@ static int obj2ast_bool(PyObject* obj, bool* out, PyArena* arena)
return 0;
}
+static int add_ast_fields()
+{
+ PyObject *empty_tuple, *d;
+ if (PyType_Ready(&AST_type) < 0)
+ return -1;
+ d = AST_type.tp_dict;
+ empty_tuple = PyTuple_New(0);
+ if (!empty_tuple ||
+ PyDict_SetItemString(d, "_fields", empty_tuple) < 0 ||
+ PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) {
+ Py_XDECREF(empty_tuple);
+ return -1;
+ }
+ Py_DECREF(empty_tuple);
+ return 0;
+}
+
static int init_types(void)
{
static int initialized;
if (initialized) return 1;
+ if (add_ast_fields() < 0) return 0;
mod_type = make_type("mod", &AST_type, NULL, 0);
if (!mod_type) return 0;
if (!add_attributes(mod_type, NULL, 0)) return 0;