From 180e63507dde824afb48ea9c1649755b79258935 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 22 Jul 2011 11:09:07 -0500 Subject: [PATCH] None is ok for identifiers but not strings --- Parser/asdl_c.py | 18 ++++++++---------- Python/Python-ast.c | 18 ++++++++---------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py index 65983751725..8a7f8aec7f4 100755 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -794,24 +794,22 @@ static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) return 0; } -static int obj2ast_stringlike(PyObject* obj, PyObject** out, PyArena* arena, - const char *name) +static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) { - if (!PyUnicode_CheckExact(name)) { - PyErr_Format(PyExc_TypeError, "AST %s must be of type str", name); + if (!PyUnicode_CheckExact(obj) && obj != Py_None) { + PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); return 1; } return obj2ast_object(obj, out, arena); } -static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) -{ - return obj2ast_stringlike(obj, out, arena, "identifier"); -} - static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) { - return obj2ast_stringlike(obj, out, arena, "string"); + if (!PyUnicode_CheckExact(obj)) { + PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); + return 1; + } + return obj2ast_object(obj, out, arena); } static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) diff --git a/Python/Python-ast.c b/Python/Python-ast.c index ea6a2ecf525..8ba06ff39a4 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -600,24 +600,22 @@ static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) return 0; } -static int obj2ast_stringlike(PyObject* obj, PyObject** out, PyArena* arena, - const char *name) +static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) { - if (!PyUnicode_CheckExact(name)) { - PyErr_Format(PyExc_TypeError, "AST %s must be of type str", name); + if (!PyUnicode_CheckExact(obj) && obj != Py_None) { + PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); return 1; } return obj2ast_object(obj, out, arena); } -static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) -{ - return obj2ast_stringlike(obj, out, arena, "identifier"); -} - static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) { - return obj2ast_stringlike(obj, out, arena, "string"); + if (!PyUnicode_CheckExact(obj)) { + PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); + return 1; + } + return obj2ast_object(obj, out, arena); } static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)