-
-
Notifications
You must be signed in to change notification settings - Fork 35k
bpo-40631: Single-element starred elements in parenthesised expressions cannot be parsed #24014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,7 @@ _PyPegen_parse(Parser *p) | |
| ''' | ||
| file[mod_ty]: a=[statements] ENDMARKER { _PyPegen_make_module(p, a) } | ||
| interactive[mod_ty]: a=statement_newline { Interactive(a, p->arena) } | ||
| eval[mod_ty]: a=expressions NEWLINE* ENDMARKER { Expression(a, p->arena) } | ||
| eval[mod_ty]: a=star_expressions NEWLINE* ENDMARKER { Expression(a, p->arena) } | ||
| func_type[mod_ty]: '(' a=[type_expressions] ')' '->' b=expression NEWLINE* ENDMARKER { FunctionType(a, b, p->arena) } | ||
| fstring[expr_ty]: star_expressions | ||
|
|
||
|
|
@@ -311,18 +311,22 @@ block[asdl_stmt_seq*] (memo): | |
| | simple_stmts | ||
| | invalid_block | ||
|
|
||
| star_element[expr_ty]: | ||
| | '*' a=bitwise_or { _Py_Starred(a, Load, EXTRA) } | ||
| | '(' '*' a=bitwise_or ')' { _Py_Starred(a, Load, EXTRA) } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This patch makes |
||
|
|
||
| star_expressions[expr_ty]: | ||
| | a=star_expression b=(',' c=star_expression { c })+ [','] { | ||
| _Py_Tuple(CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, a, b)), Load, EXTRA) } | ||
| | a=star_expression ',' { _Py_Tuple(CHECK(asdl_expr_seq*, _PyPegen_singleton_seq(p, a)), Load, EXTRA) } | ||
| | star_expression | ||
| star_expression[expr_ty] (memo): | ||
| | '*' a=bitwise_or { _Py_Starred(a, Load, EXTRA) } | ||
| | star_element | ||
| | expression | ||
|
|
||
| star_named_expressions[asdl_expr_seq*]: a[asdl_expr_seq*]=','.star_named_expression+ [','] { a } | ||
| star_named_expression[expr_ty]: | ||
| | '*' a=bitwise_or { _Py_Starred(a, Load, EXTRA) } | ||
| | star_element | ||
| | named_expression | ||
| named_expression[expr_ty]: | ||
| | a=NAME ':=' ~ b=expression { _Py_NamedExpr(CHECK(expr_ty, _PyPegen_set_expr_context(p, a, Store)), b, EXTRA) } | ||
|
|
@@ -331,11 +335,6 @@ named_expression[expr_ty]: | |
|
|
||
| annotated_rhs[expr_ty]: yield_expr | star_expressions | ||
|
|
||
| expressions[expr_ty]: | ||
| | a=expression b=(',' c=expression { c })+ [','] { | ||
| _Py_Tuple(CHECK(asdl_expr_seq*, _PyPegen_seq_insert_in_front(p, a, b)), Load, EXTRA) } | ||
| | a=expression ',' { _Py_Tuple(CHECK(asdl_expr_seq*, _PyPegen_singleton_seq(p, a)), Load, EXTRA) } | ||
| | expression | ||
| expression[expr_ty] (memo): | ||
| | a=disjunction 'if' b=disjunction 'else' c=expression { _Py_IfExp(b, a, c, EXTRA) } | ||
| | disjunction | ||
|
|
||
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
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/Core and Builtins/2020-12-30-21-13-43.bpo-40631.ejfreV.rst
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fix a bug in the PEG parser that prevents parsing tuples with | ||
| single-element, parenthesized unpacking. Patch by Pablo Galindo |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lysnikolaou Do you remember why this was
expressionsand notstar_expressions? I cannot see any edge case that makes this change incorrect but now I am curious.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this was for consistency with 3.8. While 3.8 and 3.9 currently fail at parser level for
eval('*a'), this patch fails at bytecode compiler level.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could make that fail at the parser level if you want but not sure if is worth it because we would need to factor that into some rule and I don't know if we can reuse the rest. What's your opinion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't leaving it as is work?
The reason I'm pushing for the error to be in parser level is due to the quality of the error message. Here's an example:
Without this patch:
With this patch:
The first one makes a much better job of making clear what the error is I feel. But if it's too much effort and leaving it as is doesn't work, I'm okay with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I very much agree. I have closed the PR based on this discussion and Guido's request. Thanks for the examples and the comment.