bpo-40334: Support type comments (GH-19780)

This implements full support for # type: <type> comments, # type: ignore <stuff> comments, and the func_type parsing mode for ast.parse() and compile().

Closes https://github.com/we-like-parsers/cpython/issues/95.

(For now, you need to use the master branch of mypy, since another issue unique to 3.9 had to be fixed there, and there's no mypy release yet.)

The only thing missing is `feature_version=N`, which is being tracked in https://github.com/we-like-parsers/cpython/issues/124.
This commit is contained in:
Guido van Rossum 2020-04-30 12:12:19 -07:00 committed by GitHub
parent efb8dd5b3e
commit c001c09e90
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 3451 additions and 2332 deletions

View file

@ -816,12 +816,8 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
if (str == NULL)
goto error;
int current_use_peg = PyInterpreterState_Get()->config._use_peg_parser;
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);
PyInterpreterState_Get()->config._use_peg_parser = current_use_peg;
Py_XDECREF(source_copy);
goto finally;