[3.10] bpo-44305: Improve syntax error for try blocks without except or finally (GH-26523) (GH-26524)

(cherry picked from commit b250f89bb7)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
This commit is contained in:
Pablo Galindo 2021-06-04 00:11:43 +01:00 committed by GitHub
parent 3283bf4519
commit e53f72a1b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 554 additions and 440 deletions

View file

@ -882,6 +882,14 @@ leading to spurious errors.
Traceback (most recent call last):
SyntaxError: cannot assign to attribute here. Maybe you meant '==' instead of '='?
Custom error messages for try blocks that are not followed by except/finally
>>> try:
... x = 34
...
Traceback (most recent call last):
SyntaxError: expected 'except' or 'finally' block
Ensure that early = are not matched by the parser as invalid comparisons
>>> f(2, 4, x=34); 1 $ 2
Traceback (most recent call last):