]> granicus.if.org Git - python/commitdiff
None is ok for identifiers but not strings
authorBenjamin Peterson <benjamin@python.org>
Fri, 22 Jul 2011 16:09:07 +0000 (11:09 -0500)
committerBenjamin Peterson <benjamin@python.org>
Fri, 22 Jul 2011 16:09:07 +0000 (11:09 -0500)
Parser/asdl_c.py
Python/Python-ast.c

index 65983751725159264c1dd55df990e20912243511..8a7f8aec7f4b13f45c6ff80924057af264fe8bae 100755 (executable)
@@ -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)
index ea6a2ecf525b5473c61247d80447c3295ed0b401..8ba06ff39a4b709b6a6ab12108989f43fd3343c5 100644 (file)
@@ -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)