summaryrefslogtreecommitdiffstats
path: root/Python/Python-ast.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-07-22 15:50:23 (GMT)
committerBenjamin Peterson <benjamin@python.org>2011-07-22 15:50:23 (GMT)
commit2193d2b72bc942a0c0b489a9c2759a6aefbeecdf (patch)
tree76d553c58f5e909d09aef21e6131ec797e72c3d7 /Python/Python-ast.c
parent996f606787a7aba177f738157acd672b5821be4c (diff)
downloadcpython-2193d2b72bc942a0c0b489a9c2759a6aefbeecdf.zip
cpython-2193d2b72bc942a0c0b489a9c2759a6aefbeecdf.tar.gz
cpython-2193d2b72bc942a0c0b489a9c2759a6aefbeecdf.tar.bz2
type check AST strings and identifiers
This is related to a21829180423 as well as #12609 and #12610.
Diffstat (limited to 'Python/Python-ast.c')
-rw-r--r--Python/Python-ast.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index 2c09f96..43dcf6a 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -2,7 +2,7 @@
/*
- __version__ 82163.
+ __version__ .
This module must be committed separately after each AST grammar change;
The __version__ number is set to the revision number of the commit
@@ -600,8 +600,25 @@ static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
return 0;
}
-#define obj2ast_identifier obj2ast_object
-#define obj2ast_string obj2ast_object
+static int obj2ast_stringlike(PyObject* obj, PyObject** out, PyArena* arena,
+ const char *name)
+{
+ if (!PyUnicode_CheckExact(name)) {
+ PyErr_Format(PyExc_TypeError, "AST %s must be of type str", name);
+ 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");
+}
static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
{
@@ -6739,7 +6756,7 @@ PyInit__ast(void)
NULL;
if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
return NULL;
- if (PyModule_AddStringConstant(m, "__version__", "82163") < 0)
+ if (PyModule_AddStringConstant(m, "__version__", "") < 0)
return NULL;
if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return
NULL;