gh-94192: Fix error for dictionary literals with invalid expression as value. (GH-94304)

* Fix error for dictionary literals with invalid expression as value.

* Remove trailing whitespace
(cherry picked from commit 8c237a7a71)

Co-authored-by: wookie184 <wookie1840@gmail.com>
This commit is contained in:
Miss Islington (bot) 2022-06-26 12:07:02 -07:00 committed by GitHub
parent 1b27ec5ac6
commit 442dd8ffa5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 525 additions and 449 deletions

View file

@ -1314,4 +1314,4 @@ invalid_kvpair:
| a=expression !(':') {
RAISE_ERROR_KNOWN_LOCATION(p, PyExc_SyntaxError, a->lineno, a->end_col_offset - 1, a->end_lineno, -1, "':' expected after dictionary key") }
| expression ':' a='*' bitwise_or { RAISE_SYNTAX_ERROR_STARTING_FROM(a, "cannot use a starred expression in a dictionary value") }
| expression a=':' {RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "expression expected after dictionary key and ':'") }
| expression a=':' &('}'|',') {RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "expression expected after dictionary key and ':'") }

View file

@ -1265,12 +1265,22 @@ Incomplete dictionary literals
Traceback (most recent call last):
SyntaxError: expression expected after dictionary key and ':'
# Ensure that the error is not raise for syntax errors that happen after sets
# Ensure that the error is not raised for syntax errors that happen after sets
>>> {1} $
Traceback (most recent call last):
SyntaxError: invalid syntax
# Ensure that the error is not raised for invalid expressions
>>> {1: 2, 3: foo(,), 4: 5}
Traceback (most recent call last):
SyntaxError: invalid syntax
>>> {1: $, 2: 3}
Traceback (most recent call last):
SyntaxError: invalid syntax
Specialized indentation errors:
>>> while condition:

View file

@ -0,0 +1 @@
Fix error for dictionary literals with invalid expression as value.

959
Parser/parser.c generated

File diff suppressed because it is too large Load diff