]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
bpo-40334: Add support for feature_version in new PEG parser (GH-19827)
authorLysandros Nikolaou <lisandrosnik@gmail.com>
Fri, 1 May 2020 03:27:52 +0000 (06:27 +0300)
committerGitHub <noreply@github.com>
Fri, 1 May 2020 03:27:52 +0000 (20:27 -0700)
commit3e0a6f37dfdd595be737baae00ec0e036a912615
tree42c810af16c6e84aa38aa31c30aebd1d0a9671f3
parenteb0d359b4b0e14552998e7af771a088b4fd01745
bpo-40334: Add support for feature_version in new PEG parser (GH-19827)

`ast.parse` and `compile` support a `feature_version` parameter that
tells the parser to parse the input string, as if it were written in
an older Python version.
The `feature_version` is propagated to the tokenizer, which uses it
to handle the three different stages of support for `async` and
`await`. Additionally, it disallows the following at parser level:
- The '@' operator in < 3.5
- Async functions in < 3.5
- Async comprehensions in < 3.6
- Underscores in numeric literals in < 3.6
- Await expression in < 3.5
- Variable annotations in < 3.6
- Async for-loops in < 3.5
- Async with-statements in < 3.5
- F-strings in < 3.6

Closes we-like-parsers/cpython#124.
Grammar/python.gram
Lib/test/test_type_comments.py
Parser/pegen/parse.c
Parser/pegen/parse_string.c
Parser/pegen/pegen.c
Parser/pegen/pegen.h