bpo-45292: [PEP-654] add except* (GH-29581)

This commit is contained in:
Irit Katriel 2021-12-14 16:48:15 +00:00 committed by GitHub
parent 850aefc2c6
commit d60457a667
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 7070 additions and 3332 deletions

View file

@ -955,6 +955,48 @@ Custom error messages for try blocks that are not followed by except/finally
Traceback (most recent call last):
SyntaxError: expected 'except' or 'finally' block
Custom error message for try block mixing except and except*
>>> try:
... pass
... except TypeError:
... pass
... except* ValueError:
... pass
Traceback (most recent call last):
SyntaxError: cannot have both 'except' and 'except*' on the same 'try'
>>> try:
... pass
... except* TypeError:
... pass
... except ValueError:
... pass
Traceback (most recent call last):
SyntaxError: cannot have both 'except' and 'except*' on the same 'try'
>>> try:
... pass
... except TypeError:
... pass
... except TypeError:
... pass
... except* ValueError:
... pass
Traceback (most recent call last):
SyntaxError: cannot have both 'except' and 'except*' on the same 'try'
>>> try:
... pass
... except* TypeError:
... pass
... except* TypeError:
... pass
... except ValueError:
... pass
Traceback (most recent call last):
SyntaxError: cannot have both 'except' and 'except*' on the same 'try'
Ensure that early = are not matched by the parser as invalid comparisons
>>> f(2, 4, x=34); 1 $ 2
Traceback (most recent call last):
@ -1068,6 +1110,13 @@ Specialized indentation errors:
Traceback (most recent call last):
IndentationError: expected an indented block after 'except' statement on line 3
>>> try:
... something()
... except* A:
... pass
Traceback (most recent call last):
IndentationError: expected an indented block after 'except*' statement on line 3
>>> try:
... something()
... except A:
@ -1077,6 +1126,15 @@ Specialized indentation errors:
Traceback (most recent call last):
IndentationError: expected an indented block after 'finally' statement on line 5
>>> try:
... something()
... except* A:
... pass
... finally:
... pass
Traceback (most recent call last):
IndentationError: expected an indented block after 'finally' statement on line 5
>>> with A:
... pass
Traceback (most recent call last):
@ -1180,6 +1238,48 @@ raise a custom exception
SyntaxError: multiple exception types must be parenthesized
>>> try:
... pass
... except* A, B:
... pass
Traceback (most recent call last):
SyntaxError: multiple exception types must be parenthesized
>>> try:
... pass
... except* A, B, C:
... pass
Traceback (most recent call last):
SyntaxError: multiple exception types must be parenthesized
>>> try:
... pass
... except* A, B, C as blech:
... pass
Traceback (most recent call last):
SyntaxError: multiple exception types must be parenthesized
>>> try:
... pass
... except* A, B, C as blech:
... pass
... finally:
... pass
Traceback (most recent call last):
SyntaxError: multiple exception types must be parenthesized
Custom exception for 'except*' without an exception type
>>> try:
... pass
... except* A as a:
... pass
... except*:
... pass
Traceback (most recent call last):
SyntaxError: expected one or more exception types
>>> f(a=23, a=234)
Traceback (most recent call last):
...