diff options
author | Guido van Rossum <guido@python.org> | 2019-01-31 11:40:27 (GMT) |
---|---|---|
committer | Ćukasz Langa <lukasz@langa.pl> | 2019-01-31 11:40:27 (GMT) |
commit | dcfcd146f8e6fc5c2fc16a4c192a0c5f5ca8c53c (patch) | |
tree | 07829c4f286194d0e3d08151a26ef1f3494a849b /Parser/asdl_c.py | |
parent | d97daebfa69b4df95231bcae4123eacad6a48d14 (diff) | |
download | cpython-dcfcd146f8e6fc5c2fc16a4c192a0c5f5ca8c53c.zip cpython-dcfcd146f8e6fc5c2fc16a4c192a0c5f5ca8c53c.tar.gz cpython-dcfcd146f8e6fc5c2fc16a4c192a0c5f5ca8c53c.tar.bz2 |
bpo-35766: Merge typed_ast back into CPython (GH-11645)
Diffstat (limited to 'Parser/asdl_c.py')
-rw-r--r-- | Parser/asdl_c.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py index 8640b29..a51a5db 100644 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -890,6 +890,15 @@ static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) return obj2ast_object(obj, out, arena); } +static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) +{ + if (!PyUnicode_CheckExact(obj) && !PyBytes_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) { int i; @@ -993,6 +1002,8 @@ class ASTModuleVisitor(PickleVisitor): self.emit('if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return NULL;', 1) self.emit('if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0)', 1) self.emit("return NULL;", 2) + self.emit('if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0)', 1) + self.emit("return NULL;", 2) for dfn in mod.dfns: self.visit(dfn) self.emit("return m;", 1) @@ -1176,18 +1187,19 @@ PyObject* PyAST_mod2obj(mod_ty t) } /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ +/* and 3 for "func_type" */ mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) { mod_ty res; PyObject *req_type[3]; - char *req_name[] = {"Module", "Expression", "Interactive"}; + char *req_name[] = {"Module", "Expression", "Interactive", "FunctionType"}; int isinstance; req_type[0] = (PyObject*)Module_type; req_type[1] = (PyObject*)Expression_type; req_type[2] = (PyObject*)Interactive_type; - assert(0 <= mode && mode <= 2); + assert(0 <= mode && mode <= 3); if (!init_types()) return NULL; |