summaryrefslogtreecommitdiffstats
path: root/Python/Python-ast.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-07-22 16:09:07 (GMT)
committerBenjamin Peterson <benjamin@python.org>2011-07-22 16:09:07 (GMT)
commit180e63507dde824afb48ea9c1649755b79258935 (patch)
treef3b25ac82890c7114d271df4ef4d8ddcffb7c98c /Python/Python-ast.c
parentefad2449fc14501fd4e98cb120ac0c19f82d4e78 (diff)
downloadcpython-180e63507dde824afb48ea9c1649755b79258935.zip
cpython-180e63507dde824afb48ea9c1649755b79258935.tar.gz
cpython-180e63507dde824afb48ea9c1649755b79258935.tar.bz2
None is ok for identifiers but not strings
Diffstat (limited to 'Python/Python-ast.c')
-rw-r--r--Python/Python-ast.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index ea6a2ec..8ba06ff 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)