Mercurial > cpython-lru_cache-weakref
diff Python/Python-ast.c @ 71458:c9ebae3285e3 3.2
None is ok for identifiers but not strings
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Fri, 22 Jul 2011 11:09:07 -0500 |
| parents | 08932ec9ddb1 |
| children | c8b6d4417274 d3f0f72c31f8 |
line wrap: on
line diff
--- a/Python/Python-ast.c Fri Jul 22 10:39:12 2011 -0500 +++ b/Python/Python-ast.c Fri Jul 22 11:09:07 2011 -0500 @@ -600,24 +600,22 @@ 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)
