bpo-40334: Add support for feature_version in new PEG parser#19827
Merged
gvanrossum merged 2 commits intopython:masterfrom May 1, 2020
Merged
bpo-40334: Add support for feature_version in new PEG parser#19827gvanrossum merged 2 commits intopython:masterfrom
gvanrossum merged 2 commits intopython:masterfrom
Conversation
`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#124.
gvanrossum
approved these changes
May 1, 2020
Member
gvanrossum
left a comment
There was a problem hiding this comment.
Thanks! This looks pretty straightforward.
Comment on lines
+163
to
+166
| | 'for' t=star_targets 'in' ex=star_expressions ':' tc=[TYPE_COMMENT] b=block el=[else_block] { | ||
| _Py_For(t, ex, b, el, NEW_TYPE_COMMENT(p, tc), EXTRA) } | ||
| | ASYNC 'for' t=star_targets 'in' ex=star_expressions ':' tc=[TYPE_COMMENT] b=block el=[else_block] { | ||
| CHECK_VERSION(5, "Async for loops are", _Py_AsyncFor(t, ex, b, el, NEW_TYPE_COMMENT(p, tc), EXTRA)) } |
Member
There was a problem hiding this comment.
Heh. After all my efforts to combine the two rules... :-) (Seriously, it's probably clearer this way anyways.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ast.parseandcompilesupport afeature_versionparameter thattells the parser to parse the input string, as if it were written in
an older Python version.
The
feature_versionis propagated to the tokenizer, which uses itto handle the three different stages of support for
asyncandawait. Additionally, it disallows the following at parser level:Closes we-like-parsers#124.
https://bugs.python.org/issue40334