comparison Python/Python-ast.c @ 49551:dbd54bac0b6f legacy-trunk

Fixed #4067 by implementing _attributes and _fields for the AST root node.
author Armin Ronacher <armin.ronacher@active-4.com>
date Sun, 19 Oct 2008 08:27:43 +0000
parents 145449109a31
children 2e38ca709b1d
comparison
equal deleted inserted replaced
49547:96e7854d7c6e 49551:dbd54bac0b6f
613 613
614 *out = (obj == Py_True); 614 *out = (obj == Py_True);
615 return 0; 615 return 0;
616 } 616 }
617 617
618 static int add_ast_fields()
619 {
620 PyObject *empty_tuple, *d;
621 if (PyType_Ready(&AST_type) < 0)
622 return -1;
623 d = AST_type.tp_dict;
624 empty_tuple = PyTuple_New(0);
625 if (!empty_tuple ||
626 PyDict_SetItemString(d, "_fields", empty_tuple) < 0 ||
627 PyDict_SetItemString(d, "_attributes", empty_tuple) < 0) {
628 Py_XDECREF(empty_tuple);
629 return -1;
630 }
631 Py_DECREF(empty_tuple);
632 return 0;
633 }
634
618 635
619 static int init_types(void) 636 static int init_types(void)
620 { 637 {
621 static int initialized; 638 static int initialized;
622 if (initialized) return 1; 639 if (initialized) return 1;
640 if (add_ast_fields() < 0) return 0;
623 mod_type = make_type("mod", &AST_type, NULL, 0); 641 mod_type = make_type("mod", &AST_type, NULL, 0);
624 if (!mod_type) return 0; 642 if (!mod_type) return 0;
625 if (!add_attributes(mod_type, NULL, 0)) return 0; 643 if (!add_attributes(mod_type, NULL, 0)) return 0;
626 Module_type = make_type("Module", mod_type, Module_fields, 1); 644 Module_type = make_type("Module", mod_type, Module_fields, 1);
627 if (!Module_type) return 0; 645 if (!Module_type) return 0;