gh-156058: Disallow lone starred expressions at the grammar level - #156059
Draft
encukou wants to merge 1 commit into
Draft
gh-156058: Disallow lone starred expressions at the grammar level#156059encukou wants to merge 1 commit into
encukou wants to merge 1 commit into
Conversation
Statements like the following (where `()` can be any
iterable -- or at the syntax level, any value):
*()
x = *()
yield *()
return *()
for _ in *(): ...
are not valid without a comma after the iterable.
These were allowed by `python.gram` and only rejected
in the codegen step. This means that the
documented "Full Grammar specification" was incomplete.
Change the grammar itself to disallow "lone" starred
expressions.
This interfered with the `invalid_legacy_expression`
rule, where in ``return i*i for _ in _`` the ``i *i``
was parsed similarly to ``print *i``, generating
"can't use starred expression here" from `*i` (before
getting to the "Missing parentheses in call" message
instead of a generic "invalid syntax".
Exclude the star in `invalid_legacy_expression` to
prevent this.
Co-authored-by: Blaise Pabon <blaise@gmail.com>
.
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.
Statements like the following (where
()can be any iterable -- or at the syntax level, any value):*()x = *()yield *()return *()for _ in *(): ...are not valid without a comma after the iterable.
These are allowed by
python.gramand only rejected in the code generation step. This means that the documented Full Grammar specification is incomplete.Change the grammar itself to disallow "lone" starred expressions.
This interfered with the
invalid_legacy_expressionrule, where inreturn i*i for _ in _thei *iwas parsed similarly toprint *i, generating "can't use starred expression here" from*i(before getting to the "Missing parentheses in call" message instead of a generic "invalid syntax".Exclude the star in
invalid_legacy_expressionto prevent this.