None is ok for identifiers but not strings

This commit is contained in:
Benjamin Peterson 2011-07-22 11:09:07 -05:00
parent efad2449fc
commit 180e63507d
2 changed files with 16 additions and 20 deletions

View File

@ -794,24 +794,22 @@ static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
return 0; return 0;
} }
static int obj2ast_stringlike(PyObject* obj, PyObject** out, PyArena* arena, static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
const char *name)
{ {
if (!PyUnicode_CheckExact(name)) { if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
PyErr_Format(PyExc_TypeError, "AST %s must be of type str", name); PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
return 1; return 1;
} }
return obj2ast_object(obj, out, arena); 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) 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) static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)

View File

@ -600,24 +600,22 @@ static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
return 0; return 0;
} }
static int obj2ast_stringlike(PyObject* obj, PyObject** out, PyArena* arena, static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
const char *name)
{ {
if (!PyUnicode_CheckExact(name)) { if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
PyErr_Format(PyExc_TypeError, "AST %s must be of type str", name); PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
return 1; return 1;
} }
return obj2ast_object(obj, out, arena); 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) 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) static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)