mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
[3.11] gh-109120: Fix syntax error in handlinh of incorrect star expressions… (#117464)
gh-109120: Fix syntax error in handlinh of incorrect star expressions (#117444)
(cherry picked from commit c97d3af239
)
This commit is contained in:
parent
cd12e6c779
commit
3bc0d2b851
4 changed files with 2894 additions and 2689 deletions
|
@ -955,6 +955,7 @@ kwargs[asdl_seq*]:
|
|||
|
||||
starred_expression[expr_ty]:
|
||||
| '*' a=expression { _PyAST_Starred(a, Load, EXTRA) }
|
||||
| '*' { RAISE_SYNTAX_ERROR("Invalid star expression") }
|
||||
|
||||
kwarg_or_starred[KeywordOrStarred*]:
|
||||
| invalid_kwarg
|
||||
|
@ -1075,8 +1076,8 @@ func_type_comment[Token*]:
|
|||
|
||||
# From here on, there are rules for invalid syntax with specialised error messages
|
||||
invalid_arguments:
|
||||
| ((','.(starred_expression | ( assignment_expression | expression !':=') !'=')+ ',' kwargs) | kwargs) ',' b='*' {
|
||||
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(b, "iterable argument unpacking follows keyword argument unpacking") }
|
||||
| ((','.(starred_expression | ( assignment_expression | expression !':=') !'=')+ ',' kwargs) | kwargs) a=',' ','.(starred_expression !'=')+ {
|
||||
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "iterable argument unpacking follows keyword argument unpacking") }
|
||||
| a=expression b=for_if_clauses ',' [args | expression for_if_clauses] {
|
||||
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, _PyPegen_get_last_comprehension_item(PyPegen_last_item(b, comprehension_ty)), "Generator expression must be parenthesized") }
|
||||
| a=NAME b='=' expression for_if_clauses {
|
||||
|
|
|
@ -1725,22 +1725,22 @@ A[*(1:2)]
|
|||
>>> A[*(1:2)]
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
SyntaxError: invalid syntax
|
||||
SyntaxError: Invalid star expression
|
||||
>>> A[*(1:2)] = 1
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
SyntaxError: invalid syntax
|
||||
SyntaxError: Invalid star expression
|
||||
>>> del A[*(1:2)]
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
SyntaxError: invalid syntax
|
||||
SyntaxError: Invalid star expression
|
||||
|
||||
A[*:] and A[:*]
|
||||
|
||||
>>> A[*:]
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
SyntaxError: invalid syntax
|
||||
SyntaxError: Invalid star expression
|
||||
>>> A[:*]
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
|
@ -1751,7 +1751,7 @@ A[*]
|
|||
>>> A[*]
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
SyntaxError: invalid syntax
|
||||
SyntaxError: Invalid star expression
|
||||
|
||||
A[**]
|
||||
|
||||
|
@ -1833,11 +1833,23 @@ Invalid bytes literals:
|
|||
|
||||
>>> f(**x, *)
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: iterable argument unpacking follows keyword argument unpacking
|
||||
SyntaxError: Invalid star expression
|
||||
|
||||
>>> f(x, *:)
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: invalid syntax
|
||||
SyntaxError: Invalid star expression
|
||||
|
||||
>>> f(x, *)
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: Invalid star expression
|
||||
|
||||
>>> f(x = 5, *)
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: Invalid star expression
|
||||
|
||||
>>> f(x = 5, *:)
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: Invalid star expression
|
||||
"""
|
||||
|
||||
import re
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Added handle of incorrect star expressions, e.g ``f(3, *)``. Patch by
|
||||
Grigoryev Semyon
|
5550
Parser/parser.c
generated
5550
Parser/parser.c
generated
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue