]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40334: Use old compiler when compile mode is func_type (GH-19692)
authorGuido van Rossum <guido@python.org>
Thu, 23 Apr 2020 22:42:56 +0000 (15:42 -0700)
committerGitHub <noreply@github.com>
Thu, 23 Apr 2020 22:42:56 +0000 (15:42 -0700)
This is invoked by mypy, using ast.parse(source, "<func_type>", "func_type"). Since the new grammar doesn't yet support the func_type_input start symbol we must use the old compiler in this case to prevent a crash.

https://bugs.python.org/issue40334

Python/bltinmodule.c

index ce3561e4c089858f2ce09e228ad491b65ccfb537..14c3e96fb51ab70bf675941b2f1501f8ea20d059 100644 (file)
@@ -817,7 +817,7 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
         goto error;
 
     int current_use_peg = PyInterpreterState_Get()->config._use_peg_parser;
-    if (flags & PyCF_TYPE_COMMENTS || feature_version >= 0) {
+    if (flags & PyCF_TYPE_COMMENTS || feature_version >= 0 || compile_mode == 3) {
         PyInterpreterState_Get()->config._use_peg_parser = 0;
     }
     result = Py_CompileStringObject(str, filename, start[compile_mode], &cf, optimize);