From 2c55c597faf023a0b74aa48f911493c010f464c5 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 30 Mar 2008 19:00:49 +0000 Subject: Make _fields attr for no fields consistent with _attributes attr. --- Lib/test/test_ast.py | 3 +++ Parser/asdl_c.py | 11 +++-------- Python/Python-ast.c | 11 +++-------- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index 4184bc6..e068b0a 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -163,6 +163,9 @@ class AST_Tests(unittest.TestCase): self.assertEquals(x.right, 3) self.assertEquals(x.lineno, 0) + # this used to fail because Sub._fields was None + x = _ast.Sub() + def test_main(): test_support.run_unittest(AST_Tests) diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py index 91196df..08592bc 100755 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -674,14 +674,9 @@ static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int { PyObject *fnames, *result; int i; - if (num_fields) { - fnames = PyTuple_New(num_fields); - if (!fnames) return NULL; - } else { - fnames = Py_None; - Py_INCREF(Py_None); - } - for(i=0; i < num_fields; i++) { + fnames = PyTuple_New(num_fields); + if (!fnames) return NULL; + for (i = 0; i < num_fields; i++) { PyObject *field = PyString_FromString(fields[i]); if (!field) { Py_DECREF(fnames); diff --git a/Python/Python-ast.c b/Python/Python-ast.c index c44ce38..d473418 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -465,14 +465,9 @@ static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int { PyObject *fnames, *result; int i; - if (num_fields) { - fnames = PyTuple_New(num_fields); - if (!fnames) return NULL; - } else { - fnames = Py_None; - Py_INCREF(Py_None); - } - for(i=0; i < num_fields; i++) { + fnames = PyTuple_New(num_fields); + if (!fnames) return NULL; + for (i = 0; i < num_fields; i++) { PyObject *field = PyString_FromString(fields[i]); if (!field) { Py_DECREF(fnames); -- cgit v0.12