mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-43823: Improve syntax errors for invalid dictionary literals (GH-25378)
This commit is contained in:
parent
23acadcc1c
commit
da74350174
4 changed files with 934 additions and 475 deletions
|
@ -880,6 +880,38 @@ Ensure that early = are not matched by the parser as invalid comparisons
|
|||
Traceback (most recent call last):
|
||||
SyntaxError: invalid syntax
|
||||
|
||||
Incomplete dictionary literals
|
||||
|
||||
>>> {1:2, 3:4, 5}
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: ':' expected after dictionary key
|
||||
|
||||
>>> {1:2, 3:4, 5:}
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: expression expected after dictionary key and ':'
|
||||
|
||||
>>> {1: *12+1, 23: 1}
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: cannot use a starred expression in a dictionary value
|
||||
|
||||
>>> {1: *12+1}
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: cannot use a starred expression in a dictionary value
|
||||
|
||||
>>> {1: 23, 1: *12+1}
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: cannot use a starred expression in a dictionary value
|
||||
|
||||
>>> {1:}
|
||||
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
|
||||
|
||||
>>> {1} $
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: invalid syntax
|
||||
|
||||
Make sure that the old "raise X, Y[, Z]" form is gone:
|
||||
>>> raise X, Y
|
||||
Traceback (most recent call last):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue